vbScript Validate Checkbox

S

Scott

I'm trying to validate a checkbox below on Sumbit. If the checkbox named
"myForm.myCheckBox" isn't checked, then the code in CODE 1 displays
False, which is correct.

However, when I test that same value in an IF statement in CODE 2, the IF
part doesn't catch the false. I'm also having trouble if the user clicks
yes. On the line with "myForm.myCheckBox.value= True", which should check
the box for the user, it doesn't select the checkbox control.


CODE 1 ***************
Alert "Checkbox Value= " & myForm.myCheckBox.value, vbExclamation,
"Test"


CODE 2 **************

<SCRIPT TYPE="text/vbscript" LANGUAGE="VBScript">

Function myForm_OnSubmit()

If myForm.myCheckBox.value= "False" Then

Alert "Checkbox Value= " & myForm.myCheckBox.value, vbExclamation,
"Test"

result=MsgBox ("To complete the test, you " & vbCrlf & _
"must check the box! " & vbCrlf & vbCrlf & _
"Do you want to correct this?",vbYesNo+vbQuestion,"myQuestion")
Select Case result
Case 6
myForm_OnSubmit = False
myForm.myCheckBox.value= True
Case 7 ' user cancelled

End Select
End If

End Function
</SCRIPT>
 
E

Elyo Ravuna

Dear Scott, You have to use myCheckBox.checked instead of myCheckBox.value.

myCheckBox.checked is boolean, so you also need to remove the double quotes
from the "false" keyword.

I hope it helps, please let me know if you encounter any difficulties.

Best regards.
Elyo Ravuna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top