Skip to main content

How to deselect all the selection in a select ( combo ) box?

In a HTML page sometimes we may have to deslect all the selection in a select control of html. but as a user we can't do anything. But using Javascript programatically we can achieve this. Here is the sample code in Javascript.


function clearSelect( selectObj ){
for (var i = 0; i < selectObj .options.length; i++) {
selectObj .options[i].selected = false;
}
}

note: we need to pass the select object as a parameter to this function.

the alternative to this code is
function clearSelect( selectObj ){
selectObj.selectedIndex = -1;
}

Comments

Anonymous said…
Good post and this post helped me alot in my college assignement. Thanks you seeking your information.
Anonymous said…
Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

Popular posts from this blog