I have a value, call it a, and a select box with id = "sid". I'm in javascript and want to know if my value a is one of the options in the select box.
I got this far: HTML:
<select id = "sid">
<option>a</option>
<option>b</option>
</select>
<script>
isThere('sid')
</script>
Javascript:
function isthere(id) {
var x = document.getElementById(id).options;
for (j = 0; j<= 1; j++) {
alert ("arr is " + x[j].text );
}
var c = x.text.indexOf("a");
alert ("c is " + c);
}
The loop gives the right answers for x[j].text. I don't get a value for c. Firebug gives me the error "x.text is undefined".
What is the right way to use indexOf find out if "a" is in this select box? And efficiency-wise, would I be better off just looping through x.text[j]?
candx.textis not in the loop. Must bex[j].textby the wayxis aNodeList.NodeLists don't have a propertytext.xis anHTMLOptionsCollection. But yeah there's notextproperty.