I am using a asp drop down list. According to my requirement I need to set the values of that drop down list through external java script file. How is it possible? I will not use document object to get the drop down Id.
1 Answer
If you can set up the list of option values as a js array then you can use jQuery's $.each method to build the dropdown like this
HTML
<select id="drop"></select>
JQuery
var values = ['test1','test2','test3','test4','test5','test6'];
$.each(values,function(i,val){
$('<option />').text(val).val(val).appendTo('#drop');
});
1 Comment
P.Muralikrishna
Thank you for your answer. But i am using ASP dropdown list. Please provide me the code snippet for the corresponding. Thanks in advance.
listControl.Itemsshould only contain items you add in code-behind or that are restored from ViewState. You'll have to figure out which items are selected some other way. (E.g. directly from the HTTP request.)J querycode to implement the above functionality. Please provide me the sample code snippet.That will help me a lot. Thanks in advance.C#language for coding and in the page I am usingaspx controls. Please provide the sample code.