Change value of a drop-down list with jQuery
If you need to change the value of a drop-down list as a result of another event (for example clicking on a link):
<form>
<select name="myList">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<a href="javascript:void(0)" id="option1">Select option 1</a>
<a href="javascript:void(0)" id="option2">Select option 2</a>
<a href="javascript:void(0)" id="option3">Select option 3</a>
</form>
<script>
$('#option1').click(function() {
$('select[name=myList] option[value=1]').attr('selected', 'selected');
});
$('#option2').click(function() {
$('select[name=myList] option[value=2]').attr('selected', 'selected');
});
$('#option3').click(function() {
$('select[name=myList] option[value=3]').attr('selected', 'selected');
});
</script>
Example:
Latest news
- - S5 Slide Show System: PowerPoint on Linux
- - µTorrent for Linux
- - Linux audio tagger
- - Gnome 3 release date - interview with Stormy Peters
- - Ubuntu Maverick Meerkat Beta Released
- - Ubuntu Maverick Meerkat frozen
- - Tab Candy for Firefox
- - Ubuntu font launched for beta testing
- - Interview with Richard Stallman
- - Linux Mint 9 KDE released
- - Gnome 3 release date delayed to march 2011