DropDownList's SelectedValue in JavaScript

Ok, I've forgotten this more times than I care to remember, and each time, I have to re-Google it.  I hereby commit it to digital memory:

If you have a DropDownList control like so:
     <asp:DropDownList ID="mycontrol" runat="server"></asp:DropDownList>

and you want to get it's selected value in JavaScript, do it like so:
     var control = $get('<%= this.mycontrol.ClientID %>');
     var selectedvalue = control.options[control.selectedIndex].value;

And there ya have it.  I hereby have forgotten it already... :D

Rob

posted @ Wednesday, February 27, 2008 5:48 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 8 and 4 and type the answer here:
 

Live Comment Preview: