|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
vbScript Validate Checkbox
"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> 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 Show quote "Scott" wrote: > 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> > > > > > |
|||||||||||||||||||||||