javascript - How to check if a select field has a certain option value without jQuery -
how check if option particular value exists in select field?
<select> <option value="o1">option 1</option> <option value="o2">option 2</option> </select> if select has value "o1" = true
if select has value "o4" = false
you can loop on options , check values:
var select = document.getelementbyid('selectid') || document.forms[formname or index].elements[selectname or index]; var options = select.options (var i=0, ilen=options.length; i<ilen; i++) { if (options[i].value == 'foo') { // found option value 'foo' } }
Comments
Post a Comment