dropdown item access thro' Javascript
-
I have a web control which is a dropdown list box (created & populated in VB.NET) - I want to be able to manipulate the selected value of this dropdown box based on text entered elsewhere (in another control - a textbox). For this I'd like to use the onkeyup or onkeypress methods and trigger a Javascript function which will select a particular value in the dropdown box. My dropdown box is not a typical HTML options box, but it's a VB dropdown web control. Such being the case how do I do this in Javascript? I found some code elsewhere (which I'm listing below) but this will not apply (I think) in my case - do I use some other getElement* method to get to the first item populated in the dropdown box? function searchDropdown(searchStr,ddObj) { var index = ddObj.getElementsByTagName("option"); for(var i = 0; i < index.length; i++) { if(index[i].firstChild.nodeValue.toLowerCase().substring(0,searchStr.length) == searchStr.toLowerCase()) { index[i].selected = true; break; } } }
-
I have a web control which is a dropdown list box (created & populated in VB.NET) - I want to be able to manipulate the selected value of this dropdown box based on text entered elsewhere (in another control - a textbox). For this I'd like to use the onkeyup or onkeypress methods and trigger a Javascript function which will select a particular value in the dropdown box. My dropdown box is not a typical HTML options box, but it's a VB dropdown web control. Such being the case how do I do this in Javascript? I found some code elsewhere (which I'm listing below) but this will not apply (I think) in my case - do I use some other getElement* method to get to the first item populated in the dropdown box? function searchDropdown(searchStr,ddObj) { var index = ddObj.getElementsByTagName("option"); for(var i = 0; i < index.length; i++) { if(index[i].firstChild.nodeValue.toLowerCase().substring(0,searchStr.length) == searchStr.toLowerCase()) { index[i].selected = true; break; } } }
That code is really ugly... It is designed to go trough all the options in all the selectobxes on the form. But when it finds the first item that match it breaks from searching leaving other potential mathing options (in other selectboxes) un-selected. What you should do is write a function that will take two arguments. One is search string, and the other is the ID of your select box. This function should only go trough the options of that selectbox. Then you simply add the onkeydown event and call your function from there. -------------------------------------------------------- Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!