Reputation: 2026
How to reset (back to 0 index) dropdown list on 'back' button of browser using Javascript?
Upvotes: 14
Views: 44564
Reputation: 61
yes its easy.
i have a dropbox and its id was "stroke_style" the reset is just to set it at -1 index (before 0)
document.getElementById("stroke_style").selectedIndex = -1;
example: http://languagelassi.blogspot.in/search/label/Dropdown%20Reset%20Javascript
and you can put it in a method or directly <body onload="">
of that page
Upvotes: 6
Reputation: 2026
<script type="text/javascript" language="javascript" >
var orig_default = -1;
function setDefault() {
if (orig_default < 0) {orig_default = document.getElementById("MyList").selectedIndex;}
}
function testReset() {
if (orig_default >= 0) {
document.getElementById("MyList").selectedIndex = orig_default;
}
}
</script>
<body onbeforeunload='setDefault();'>
Here are couple of scripts which I have written myself to solve the issue of resetting the value of html upon browser back button click.
Upvotes: 0
Reputation: 17636
You can use the 'onbeforeunload' event:
<script>
function reset_options() {
document.getElementById('MySelect').options.length = 0;
return true;
}
</script>
<body onbeforeunload='reset_options()'>
...
Upvotes: 8