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));
});
}
}
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
Post a Comment