Friday, March 27, 2015

JavaScript : Select a dropdown option by value


var value= "valuetoput";
var selectId =  document.getElementById("zonee")

for(var i=0; i < selectId .options.length; i++)
        {
            if(selectId .options[i].value == value)
                selectId .selectedIndex = i;
        }

selectId:This is the select box taken by functions like "getElementById" or any other way
value: This is the value which needs to be selected from the options of elmnt.

0 comments:

Post a Comment