Santhosh
Santhosh

Reputation: 20406

set/change value to drop down using jquery

how to set or change value to drop down.

I'm having a drop down list which is initially not selected a value.

How can i select a value using jquery

Upvotes: 1

Views: 1960

Answers (2)

Tommaso Taruffi
Tommaso Taruffi

Reputation: 9252

$("#id_select").val("value_1");

id_select -> is the id of your select

value_1 -> is one of the values presents in the option of select

Upvotes: 0

Jørn Schou-Rode
Jørn Schou-Rode

Reputation: 38346

The val() function is used to get and set the value of input controls (including <select>). Grab a jQuery reference to your <select>, and pass its val() function a string matching the value attribute of the <option> that you wish to select:

$("#mySelect").val("15");

This would select the second option in this list:

<select id="mySelect">
    <option value="5">Few</option>
    <option value="15">More</option>
    <option value="100">Many</option>
</select>

Upvotes: 6

Related Questions