Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count < 1 send user back to form w/pop up error msg in diff window

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
US
I have a number of checkboxes in a form, along with other data fields and need to know how to check to make sure the user has selected at least one. If the count is less than 1, they would not be sent to the second page and a window would pop up giving them an error message that at least one checkbox should be checked.

So, at submission I basically need to validate the checkbox count. Does anyone have any ideas???? Thanks!
 
javascript for loop through the form objects.
check first for the .type = "checkbox"
then validate if .checked = true

There should be no reason for you to ever call the server first to perform this type of validation. Thats why the developer gods invented client side scripting. [wink]

1H 1K 10 3D 3F 3E 3K 38 3J 10 1T 10 3G 3L 3I 35 10 35 3O 33 35 3C 3C 35 3E 33 35

brickyard.jpeg
Most intense event I ever attended!
 
I'm learning all of this as I go, so could you elaborate just a bit - how would I properly refer to .type = "checkbox" - in other words what would the prefix be? formobj.type? Fogive me, but learning.......

Thanks for the input - if I can figure it out, that should work.

This is just some of my checkbox code for the checkboxes...in case that'll help.

<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Janitorial</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Janitorial&quot; value=&quot;3400&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Lawn Equipment &amp; Accessories</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_LawnEquip&quot; value=&quot;3600&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Mail Room Equipment</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_MailRoom&quot; value=&quot;3800&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Medical</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Medical&quot; value=&quot;4000&quot;></td>
</tr>
<tr>

Thanks!!

 
Add an OnClick event to your Submit button:
<input type=&quot;submit&quot; name=&quot;btnSubmit&quot; value=&quot;submit&quot; OnClick=&quot;CheckTheBoxes()&quot;>

Then:

<script language=&quot;vbscript&quot;>
Sub CheckTheBoxes()
for x = 0 to Document.YourFormName.Elements.Length -1
If left(Document.YourFormName.Elements(x).Name,2)=&quot;ck&quot; THEN
IF Document.YourFormName.Elements(x).Checked = TRUE Then
myCounter = myCounter + 1
End IF
End IF
NEXT
If myCounter < 1 THEN
alert &quot;Please check one of the checkboxes!&quot;
window.event.returnvalue=false
Exit Sub
End IF
End Sub
</script>
 
a javascript function woul dlook something like
function chgCheckBox() {
var objForm = document.frm;
var runTotal = 0;


for(x=0;objForm.length;x++) {
if(objForm.elements[x].type == &quot;checkbox&quot;) {
if(objForm.elements[x].checked == true)
runTotal += 1;
alert(runTotal);

}
}

document.frm.runTotalCheckBoxs.value = runTotal;
}


which you may want to consider for browser reasoning
any further help on client side tech's I suggest the vbscript and javascript forums for help

1H 1K 10 3D 3F 3E 3K 38 3J 10 1T 10 3G 3L 3I 35 10 35 3O 33 35 3C 3C 35 3E 33 35

brickyard.jpeg
Most intense event I ever attended!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top