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).

Advertisements

Say something : I accept all the "Humer&Critic"

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s