473,396 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Check box validaton

17
I am a newbie to this and am having a problem with validation and keeping data that has been entered in other fields when submitting the form.
For the check boxes, I need a minimum of one selected. If one is not selected, a message box appears notifying that a check box has not been selected. When I click OK, the data in the other text boxes is removed as if the form is being reloaded. How can I prevent this from happening.
Is there a better way to validate the checkboxes. I have searched and most instances of validation refer to linking to an outside validation jsp. This can not be done for this situation. Any help would be most appreciated.


[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
function validate(){
var A = document.forms[0].elements['OBKey_Generic_Field_01_1'];
var B = document.forms[0].elements['OBKey_Generic_Field_02_1'];
var C = document.forms[0].elements['OBKey_Generic_Field_03_1'];
var D = document.forms[0].elements['OBKey_Generic_Field_05_1'];

if (A.checked == 1){
alert("Are you sure you want to submit form?");
return false;
}
if (B.checked == 1){
alert("Are you sure you want to submit form?");
return false;
}
if (C.checked == 1){
alert("Are you sure you want to submit form?");
return false;
}
if (D.checked == 1){
alert("Are you sure you want to submit form?");
return false;
}

else
alert("You must select type of additional documentation submitted")
}

</script>




</head>
<form action="" method="post" name="ACH" onSubmit="return validate();" >
<body>
<table width="905" border="0" cellpadding="1" cellspacing="1" class="h1">
<tr>
<td width="145" class="text" height="28"><div align="right">
<div align="right">Bank Name:&nbsp;</div>
</div></td>
<td width="314" height="28"><input class="text" name="OBKey__206_1" size="50" tabindex="6"></td>
<td width="214" class="text" height="28"><div align="left">&nbsp;&nbsp;&nbsp; ABA # (must be 9 digits:&nbsp; </div></td>
<td width="219" height="28" ><div align="left">
<input name="OBKey__60_1" type="text" size="9" maxlength="9" tabindex="7" >
</div></td>
</tr>

</table>
<tr>
<td ><hr></td>
</tr>
<table width="901" border="0" cellpadding="1" cellspacing="1" class="h1">
<tr>
<td width="250" height="22" class="h2A">VI. Additional documentation submitted:</td>
<td width="644" height="22" colspan="2" class="text"><input name="OBKey_Generic_Field_01_1" value="ON" type="checkbox" tabindex="10">
&nbsp;Direct Allocated (Screen Prints)</td>
</tr>
<tr>
<td width="250" height="26" class="text"></td>
<td height="26" class="text" colspan="2"><input name="OBKey_Generic_Field_02_1" value="ON"type="checkbox" tabindex="11">
&nbsp;Canceled Check Request </td>
</tr>
<tr> </tr>
<tr>
<td width="250" height="26" class="text"><div align="left" class="h2A">
<td height="26" class="text" colspan="2" valign=""><input name="OBKey_Generic_Field_03_1" value="ON" type="checkbox" tabindex="12">
&nbsp;Stop Payment Request</td>
</tr>
<tr>
<td width="250" height="35" class="text"><div align="left" class="h2A">
<td height="35" class="text" colspan="2" valign=""><input name="OBKey_Generic_Field_05_1" value="ON" type="checkbox" tabindex="13">
&nbsp;Other</td>
</tr>
<tr>
<td width="250" height="32" class="text" valign="baseline"><div align="left" class="h2A">
<td align="left" valign="top" ><input type="submit" value=Submit name="OBBtn_Save" tabindex="14" >
<input type="submit" value="Cancel" name="OBBtn_No" >
</td>
</tr>
</table>




</body>
</html>[/HTML]
Jun 17 '08 #1
1 1507
acoder
16,027 Expert Mod 8TB
Your validation is wrong way round. If one is checked, return true, not false. Also, the way to validate would be check if none of them are checked. If so, return false. At the end of the validation function, return true.

Since the checkboxes are connected, use the same name, so you can get them at once with document.getElementsByName().
Jun 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Craig Bailey | last post by:
Someone please explain what alternate universe I fell into this afternoon when PHP started telling me that 2 doesn't equal 2. Not sure about you, but when I run this, it tells me 59001.31 doesn't...
7
by: Tony Johnson | last post by:
Can you make a check box very big? It seems like when you drag it bigger the little check is still the same size. Thank you, *** Sent via Developersdex http://www.developersdex.com ***...
2
by: Travis.Box | last post by:
I have an MS Access userform with 16 Check Boxes. Each of the checkboxes has a different option value, which coincides with the Check Box name (eg. cb01.OptionValue = 1). At the bottom of the...
9
by: simonmarkjones | last post by:
I want to call a function which does this when the next record button is pressed (calling it from before update) if textboxes are empty then Message box you must fill text box
1
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
2
by: Chris Davoli | last post by:
How do you enable a check box in the GridView. I selected Checkbox Field in the Columns of the GridView, and the check box shows up in the Grid view, but it is disabled. How do I enable it so I can...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
5
by: starke1120 | last post by:
Im creating a check in – check out database for RF guns. I have a table that contains models. ID (primary key) Model A table that contains Gun Details ID (primary key) Model_id...
1
by: ghjk | last post by:
my php page has 7 check boxes. I stored checked values to database and retrive as binary values. This is the result array Array ( => 0 => 1 => 0 => 1 => 0 => 0 => 1 ) 1 means checked....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.