many of times we have requirement to add a item at top of listbox using javascript (add item at index 0).
var txtl = document.getElementById("<%= txtvalue.ClientID %>"); var lst = document.getElementById("<%=mylistbox.ClientID %>"); if(txtl.value != "") { var opt = document.createElement("Option"); opt.text =txtl.value; opt.value = txtl.value; lst.options.add(opt,0); // here while adding new item to listbox we can pass its index number. }
No comments:
Post a Comment