Search a dropdown list using JavaScript
Requirement:
I have ASP DropDownList control on my aspx page.
On button event control, I require to change index of my DropDownList control.
Below I have described the solution.
Solution:
The dropdown conrol will be like below:-
1 2 3 4 | <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>2011</asp:ListItem> <asp:ListItem>2012</asp:ListItem> </asp:DropDownList> |
The Java Script will be like below:-
1 2 3 4 5 6 7 8 9 10 | function SetDropDownControl(input, controlIDToSet) { // input = its data which need to set in dropdown // controlIDToSet = Its ASP:DropDownList control client id where input need to set var dropDownControl = document.getElementById(controlYearIDToSet).options; for (var i = 0; i < dropDownControl.length; i++) { if (dropDownControl[i].value.indexOf(input) == 0) { dropDownControl[i].selected = true; } // if loop end } // for loop end } |
Thanks!
Infoyen
May 14, 2012
В·
Infoyen В·
No Comments
Tags: DropDownList, How to get selected value of dropdownlist using JavaScript, javascript, Search a dropdown list, Select a dropdown option by value В· Posted in: JavaScript
Leave a Reply