...

View Full Version : check if any of the options value consist of



sushestvo
10-13-2005, 03:04 PM
if i have a
<select>
<option 1>
<option 2>
</select> in my html page
how can I check if any of the options consist a specific word?

rm-f
10-13-2005, 08:15 PM
<html>
<head>
<script>
function f() {
var sel = document.getElementById('sel');
for(var i=0; i<sel.childNodes.length; i++) {
if(sel.childNodes[i].text == 'rotten') {
alert('I found you! (position:' + i + ')');
}
}
}
</script>

</head>
<body>
<select id="sel">
<option>good</option>
<option>better</option>
<option>rotten</option>
</select>
<button onclick="f();">Press Me</button>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum