views:

17512

answers:

2

As the question says, how do I set the value of a DropDownList control using jQuery?

+27  A: 
$("#mydropdownlist").val("thevalue");

just make sure the value in the options tags matches the value in the val method.

Nick Berardi
nice one, thanks!
flesh
@Nick: I have a range validator against a drop down list and I am setting the value of the drop down list as you have described above, yet the range validator keeps failing telling me to select a value (when the value selected is within range). Please see my question http://stackoverflow.com/questions/3165033/rangevalidator-not-working-when-selecting-dropdownlist-value-using-jquery
James
A: 

please check this solution:: http://ledomoon.blogspot.com/2009/12/dropdown-selected-change-event-by.html

$(document).ready(
function(){
// select all the divs and make it invisible
$("div.Content").css("display","none");
// Find all the combos inside the table or gridview
$("#tblItems").find("select.Status").each(function () {
// Attached function to the change event of each combo
$(this).change(function () {
if ($(this).val() == "test1")
{
// Change the visibility of the next div after the selected combo if the selected value = test1
$(this).parent().find("div.Content").fadeIn("slow");//css("display","block");
}
else
{
$(this).parent().find("div.Content").fadeOut("slow");//.css("display","none");
}
});
});
});

Hope this helps,

Waleed Mohamed
SO much for setting a value in a drop down! :P Nick's answer is more simpler and to-the-point.
Nikhil Patil