$('.reset').click(function () {
$('select[name=one]').val(opt2);
});
JSFiddle here.
What should I change?
Thanks!
$('.reset').click(function () {
$('select[name=one]').val(opt2);
});
JSFiddle here.
What should I change?
Thanks!
Put opt2
in quotes for val()
. It's coming up as an error because it is undefined
.
$('.reset').click(function () {
$('select[name=one]').val('opt2');
});
You asked for some other methods, but I only know of one other. This method doesn't require jQuery to function (note that the [0]
grabs the normal Object
rather than an jQuery wrapped Object
).
//Without jQuery... pretty sure I'm correct with the second method, but I'm rusty on that one.
document.getElementById('formID').one.selectedIndex = 0; // Sets the select back to the first option.
document.formName.one.selectedIndex = 0;
//With jQuery
$('select[name=one]')[0].selectedIndex = 0;