tinti
tinti

Reputation: 1475

Select value on combobox with jquery

I have a combobox (select) and i want to select after a specified value something like that

$("mySelect").select(myValue);

Thanks

Upvotes: 13

Views: 71438

Answers (3)

Hero
Hero

Reputation: 197

$('#select').val('3');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="select">
    <option value="1">ABC</option>
    <option value="2">DEF</option>
    <option value="3">XYZ</option>
</select>
 

Upvotes: 0

genesis
genesis

Reputation: 50966

$("#yourselect").next().attr('selected', 'selected');

it will select next select after this one (yourselect)

so

<select id="your" />aa
<select id="yourselect" />bb
<select id="yourselect2" />cc

it'll select yourselect2

Upvotes: 0

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262919

If you want to select the <option> element associated with your value, you can use val():

<select id="mySelect">
    <option value="foo">Foo</option>
    <option value="bar">Bar</option>
    <option value="quux">Quux</option>
</select>

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

Upvotes: 34

Related Questions