I was wondering if it’s possible to get jQuery to select an <option>
, say the 4th item, in a dropdown box?
<select>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select>
I want the user to click a link, then have the <select>
box change its value, as if the user has selected it by clicking on the <option>
.
Try this:
Regards!
answer with id:
I would do it this way
How about
example at http://www.jsfiddle.net/gaby/CWvwn/
for modern versions of jquery you should use the
.prop()
instead of.attr()
example at http://jsfiddle.net/gaby/CWvwn/1763/
HTML select elements have a
selectedIndex
property that can be written to in order to select a particular option:Using plain JavaScript this can be achieved by:
Use the following code if you want to select an option with a specific value: