|
-
Feb 23rd, 2012, 01:11 AM
#1
Thread Starter
New Member
[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.
-
Feb 23rd, 2012, 09:11 AM
#2
Addicted Member
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>
-
Feb 24th, 2012, 12:33 AM
#3
Thread Starter
New Member
Re: how to check if option element exists
 Originally Posted by His Nibbs
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|