Link to home
Start Free TrialLog in
Avatar of RecipeDan
RecipeDan

asked on

Checkbox Validation

Hello:

What I am trying to do is submit the form. However if the ValueTextBox is less then or equal to 5 the form should not be submitted until the checkbox is checked.

<head>
<script type = text/vbscript>
Function theForm_onSubmit
If Document.theForm.ValueTextBox.Value <= "5"  Then
MsgBox "Please select a response!"
theForm_OnSubmit = False
Else
If Document.theForm.ValueTextBox.Value <= "5" AND Document.theForm.Ques.checked  Then
theForm_OnSubmit = True
End If
End Function
</script>
</head>
<body>
<form method="POST" name="theForm" action="abc.asp">
<input type="checkbox" name="Ques" value="Hi"><input type="text" name="ValueTextBox" size="20" value="<%=Request("NumValue")%>">
<input type="submit" value="Submit" name="B1">
</form>
</body>
Avatar of omgang
omgang
Flag of United States of America image

The first conditional will always be True when ValueTextBox <= 5 regardless of wheter the check box is checked or not.  Try reversing the conditionals.

Function theForm_onSubmit
If Document.theForm.ValueTextBox.Value <= "5" AND Document.theForm.Ques.checked  Then
theForm_OnSubmit = True
Else
If Document.theForm.ValueTextBox.Value <= "5"  Then
MsgBox "Please select a response!"
theForm_OnSubmit = False
End If
End Function

OM Gang
ASKER CERTIFIED SOLUTION
Avatar of omgang
omgang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial