vbScript Validate Checkbox

Discussion in 'ASP General' started by Scott, Sep 24, 2006.

  1. Scott

    Scott Guest

    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>
     
    Scott, Sep 24, 2006
    #1
    1. Advertising

  2. Scott

    Elyo Ravuna Guest

    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


    "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>
    >
    >
    >
    >
    >
     
    Elyo Ravuna, Sep 25, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luigi
    Replies:
    3
    Views:
    513
    Luigi
    May 7, 2009
  2. Rowena

    Validate CheckBox

    Rowena, Oct 24, 2009, in forum: ASP .Net
    Replies:
    7
    Views:
    1,689
    ponyryd
    Dec 2, 2009
  3. bobby1041
    Replies:
    1
    Views:
    570
    Bullschmidt
    Oct 5, 2005
  4. .Net Sports
    Replies:
    4
    Views:
    3,482
    Adrienne Boswell
    Sep 29, 2009
  5. bobby1041
    Replies:
    1
    Views:
    79
    Evertjan.
    Oct 3, 2005
Loading...

Share This Page