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){
          $('#'+elementId).find('option').remove().end()
            .append('<option value="-1">Select Creative Size</option>');

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

Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

How to create mail message in FRC822 format