Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset dropdown list <select> on 'back' button of browser using Javascript?

How to reset (back to 0 index) dropdown list on 'back' button of browser using Javascript?

like image 490
code master Avatar asked Nov 26 '10 17:11

code master


2 Answers

You can use the 'onbeforeunload' event:

<script>
function reset_options() {
    document.getElementById('MySelect').options.length = 0;
    return true;
}

</script>
<body onbeforeunload='reset_options()'>
...
like image 100
Don Avatar answered Nov 20 '22 21:11

Don


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

like image 44
pearl's Avatar answered Nov 20 '22 20:11

pearl's