jQuery access DropDownList

Sponsored Links

jQuery DropDownList

Here we look at jQuery DropDownList, that is using jQuery to get access to a .NET DropDownList control's selected value.

In ASP.NET, we'd probably look at the selected value of a dropdownlist on the server after a postback, however, recent trending is pushing more processing work to the browser client, so we may find ourselves actually using jQuery to view a DropDownList's selected value whilst on the client and reacting to the selection at this point in time.

jQuery DropDownList Selected Value

The code below shows how to access the .NET DropDownList's selected value:

  selectedColour = $('#DropDownList_Colour option:selected').text();

So we call jQuery, ($), specify the ID of the control using the jquery selector for id, '#' (DropDownList_Colour). 'option:selected' states a more specific target, (a DropDownList is a SELECT list of OPTIONS in HTML) so this gets the selected option, and finally .text() gets the text content of the element.