Results 1 to 3 of 3

Thread: [SOLVED]how do you check if option elements exist

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    [SOLVED]how do you check if option elements exist

    I'm creating a HTML application.

    How can you check with VBscript if option element exists in the html code?

    I have to check if there are options inside the select element like in this example:

    Code:
    <select name="LangChooser">
       <option value="sp">Spanish</option>
       <option value="en">English</option>
    </select>
    ...OR if there are not option elements like in this example:

    Code:
    <select name="LangChooser">
    </select>
    Thanks!
    Last edited by purpleglow; Feb 24th, 2012 at 12:35 AM.

  2. #2
    Addicted Member
    Join Date
    Jul 2009
    Posts
    208

    Re: how to check if option element exists

    Try something based on this:
    Code:
    <script language="VBScript">
    Option Explicit
    
    Sub CheckLang ()
    
      Dim selectElement
    	
      Set selectElement = document.getElementById("LangChooser")
    
      If selectElement.options.length = 0 Then
        alert "No options"
      Else
        alert "Number of options = " & selectElement.options.length
      End If
      
    End Sub
    
    </script>

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: how to check if option element exists

    Quote Originally Posted by His Nibbs View Post
    Try something based on this:
    Code:
    <script language="VBScript">
    Option Explicit
    
    Sub CheckLang ()
    
      Dim selectElement
    	
      Set selectElement = document.getElementById("LangChooser")
    
      If selectElement.options.length = 0 Then
        alert "No options"
      Else
        alert "Number of options = " & selectElement.options.length
      End If
      
    End Sub
    
    </script>

    Thanks a lot! Works perfectly!

Posting Permissions

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



Click Here to Expand Forum to Full Width