IT Certificaions

Google Cloud Platform

Friday, November 15, 2013

Append option into a select using jquery

You can use jquery to append data from select from a array of data. See the java script function where you can pass the dataArray like dataArray=["A","B"] and elementId , means the id attribute of your select element;

function appendDataToSelectDropDown(dataArray,elementId){
      if(dataArray !=null && dataArray.length>0){
            .append('<option value="-1">Select Creative Size</option>');

          $.each(dataArray, function( index, value ) {   
                $('#'+elementId).append(new Option(value, value));