I have a select list which is being populated using the values from a text field. I also have two buttons: an add button which adds the entered value to the select list and a re
For best answer, Try below code :
Add Options to Select Tag Using Jquery
$(document).ready(function(){
//Function To Add or Remove New Option Field in Form
var i=2;
$(".add").on("click", function add_new(){
$(".more").append($("").append(
"",
$("",{class:'add', src:'images/add.png'}).click(function(){add_new();}),
$("",{class:'del', src:'images/del.png'}).click(function(){$(this).parent().remove();})
))
i=i+1;
});
//Below Function Executes on Click of create select Button
$("#button").on("click",function(){
//To Clear Previous Select Option Field if Exists in Div
$("#prm").empty();
//Creating Select Option in Div
$("#prm").append("");
//Creating Options and Adding it To Above Select Tag
$("input[type=text]").each(function(){
if($(this).val()==""){
alert($(this).attr('id')+" is Empty !");
}
else{
$("select").append('');
}
});
});
});
http://www.formget.com/jquery-add-option-to-select/