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
2008-11-15 14:38:45
nice one, thanks!
flesh
2008-11-15 14:41:48
@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
2010-07-07 13:14:13
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
2009-12-31 10:37:20
SO much for setting a value in a drop down! :P Nick's answer is more simpler and to-the-point.
Nikhil Patil
2010-10-14 22:19:43