Is it possible to select special <option> item with jQuery by pressing button?
For example :
<a id="item1" href="#">Item 1</a>
<a id="item2" href="#">Item 2</a>
<a id="item3" href="#">Item 3</a>
<form>
.......
<select id="items" name="items">
<option value="1">I dont know</option>
<option value="2">Item 1</option>
<option value="3">Item 2</option>
<option value="4">Item 3</option>
</select>
.........
</form>
If you press the second button than in form automatically selects second option. Is it possible?
This is a simple jQuery way of doing it.
$('a').click(function() {
var select_num = $(this).index() + 1;
$('#items option').eq(select_num).attr('selected', 'selected');
});
Here is the example fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With