Reset the Value of a Select Box
I presume you only want to reset a single element. Resetting an entire form is simple: call its reset method.
The easiest way to "reset" a select element is to set its selectedIndex
property to the default value. If you know that no option is the default selected option, just set the select elemen'ts selectedIndex property to an appropriate value:
function resetSelectElement(selectElement) {
selecElement.selectedIndex = 0; // first option is selected, or
// -1 for no option selected
}
However, since one option may have the selected attribtue or otherwise be set to the default selected option, you may need to do:
function resetSelectElement(selectElement) {
var options = selectElement.options;
// Look for a default selected option
for (var i=0, iLen=options.length; i<iLen; i++) {
if (options[i].defaultSelected) {
selectElement.selectedIndex = i;
return;
}
}
// If no option is the default, select first or none as appropriate
selectElement.selectedIndex = 0; // or -1 for no option selected
}
And beware of setting attributes rather than properties, they have different effects in different browsers.
This works for me:
$('select').prop('selectedIndex', 0);
FIDDLE
Further to @RobG's pure / vanilla javascript answer, you can reset to the 'default' value with
selectElement.selectedIndex = null;
It seems -1 deselects all items, null selects the default item, and 0 or a positive number selects the corresponding index option.
Options in a select object are indexed in the order in which they are defined, starting with an index of 0.
source