Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the value of a DropDownList using jQuery?

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

like image 517
flesh Avatar asked Nov 15 '08 14:11

flesh


People also ask

How can I change the selected value of a Dropdownlist using jQuery?

Using the jQuery change() method; you can set the selected value of dropdown in jquery by using id, name, class, and tag with selected html elements; see the following example for that: Example 1 :- Set selected value of dropdown in jquery by id.

How show selected value from database in dropdown using jQuery?

Use $('select[id="salesrep"]'). val() to retrieve the selected value. Use $('select[id="salesrep"]'). val("john smith") to select a value from dropdown.

How can set the selected value of dropdown in HTML?

The select tag in HTML is used to create a dropdown list of options that can be selected. The option tag contains the value that would be used when selected. The default value of the select element can be set by using the 'selected' attribute on the required option. This is a boolean attribute.

How do I select a specific Dropdownlist using jQuery?

Syntax of jQuery Select Option$(“selector option: selected”); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $(“selector option: selected”).


2 Answers

$("#mydropdownlist").val("thevalue"); 

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

like image 89
Nick Berardi Avatar answered Sep 26 '22 16:09

Nick Berardi


As suggested by @Nick Berardi, if your changed value is not reflected on the UI front end, try:

$("#mydropdownlist").val("thevalue").change(); 
like image 34
IRSHAD Avatar answered Sep 23 '22 16:09

IRSHAD