Dropdown Reset Javascript

To reset dropdown/ or selectbox, we can simply fire this javascript code on any dom event
document.getElementById("id_of_selectbox").selectedIndex = -1;


The selectedIndex method of javascript will reset the index of the selected dropbox.

Another and better option is to create a simple function say resetDropbox and call it where-ever you want in your page.
function(id_of_dropbox){
 document.getElementById(id_of_dropbox).selectedIndex = -1;
}

Sometime we face problems, when press back button in browser and we get some value pre-selected in dropbox.
We can use binding reset scripts on jQuery's Dom Ready, that will put dropbox of the form in its normal(unselected state).

Popular posts from this blog

Fake CVR Generator Denmark

How To Iterate Dictionary Object

Bing Homepage Quiz: Fun, Win Rewards, and Brain Teasers