473,473 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

vbScript Validate Checkbox

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>


Sep 24 '06 #1
1 19103
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>


Sep 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
2
by: Scott Natwick | last post by:
I would like to validate that a Checkbox is checked on the client-side. I have tried the "requiredfieldvalidator" and the "regularexpressionvalidator", but haven't been able to get either of them...
1
by: jayparaiso | last post by:
Hi! How to validate check box and drop down menu in one form?
1
by: Bhagya | last post by:
Help me to validate a checkbox wherein i want to display different messages when the checkbox is checked and unchecked.....
11
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, I have a large recordset to be displayed on a ASP 3.0 page. I am using recordset paging for this. For the next and previous link i am passing href as <a href=<Page URl>?page=<%=...
1
by: mbarnhizer | last post by:
Hello All, Trying to figure out how to validate a series of questions on an online test. I am thinking that VB or Javascript is the best route, but your input may make a difference. The site i...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
0
by: Ned Balzer | last post by:
I posted this this morning but it never went through, so I am trying again -- apologies for the duplication if so. I need to validate several checkboxes on an asp.net 2.0 page. I don't need to...
5
by: lolodede | last post by:
i would like to make sure user at least one checkbox and if it select otherand need to make sure to write something in text box <?php $name = 0; $cusID=0; $hobbies =0 ; if (isset ($_POST)) {...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.