Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    check if any of the options value consist of

    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?

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <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>
    rm -f /


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •