javascript - how to create a select without an option by default -
i want create select without option default, have next list of languages, when select 1 , press button" addland", use .append of jquery add 1 language list, default create option empty when page executed:
<select id="langlist"> <option></option> </select>
this code, can change add new options elemets without option empty?
<select id="updlanguage"> <option value="tr">turkish</option> <option value="uk">ukrainian</option> <option value="ur">urdu</option> <option value="vi">vietnamese</option> <option value="zu">zulu</option> </select> <input type="button" id="addlang" value="addlang"> <select id="langlist"> <!--when press button "addlang" add new lang <option></empty> empty before , lang add-->
".$languages."";?> // reload languages saved in db
script add new lang list
$("#addlang").on("click", function(){ var lang =$("#updlanguage :selected").text(); var idlang =$("#updlanguage").val(); $("#langlist").append("<option id='"+idlang+"'>"+lang+"</option>"); });
this works:
$("#addlang").on("click", function(){ var lang =$("#updlanguage :selected").text(); var idlang =$("#updlanguage").val(); if($("#langlist").is("div")) { $("#langlist").replacewith($('<select id="langlist">' + this.innerhtml + '</select>')); } $("#langlist").append("<option id='"+idlang+"'>"+lang+"</option>"); });
Comments
Post a Comment