...

View Full Version : Issue with Validation code



dslegends
10-30-2012, 03:00 PM
Ok Heres the deal i have 3 check boxes 1 of them has to be checked or it will not let you submit anything but for some reason all my other validations work but this one. you have to have only 1 of the 3 check boxes checked to be able to submit here is the section im trying to get work

if (frm.sev1.checked == false){
vald += validateEmpty(frm.sev1)&& "-SEV1?\n";

}
if (frm.sev2.checked == false){
vald += validateEmpty(frm.sev2) && "-SEV2?\n";

}
if (frm.sev34.checked == false){
vald += validateEmpty(frm.sev34) && "-SEV3/4?\n";

}




Here is some of the code that does work

vald += validateEmpty(frm.Description0) && "-Incident or Task Description:\n";
vald += validateEmpty(frm.duias) && "-Discussed urgency/impact/assigned severity?\n";

Philip M
10-30-2012, 06:20 PM
Your code says that all the checkboxes must be checked.

You want

if ((frm.sev1.checked == false) && ( frm.sev2.checked == false) && (frm.sev34.checked == false)) {

i.e. if none of the boxes have been checked.

Durex Extra Safe Condoms 24-Pack.
Buy Now: £3.32
4 Used and New from £1.00.
In stock.
- Amazon

dslegends
10-30-2012, 08:19 PM
Ah you are a super master coder for a reason...i cant believe i didnt see that thank you so much this can be marked as complete or closed

Dormilich
10-31-2012, 09:17 AM
besides that, if exactly one has to be checked, use radiobuttons with one of them pre-checked. that wouldn’t even need JS.


@Philip: nice quote!

Philip M
10-31-2012, 09:39 AM
besides that, if exactly one has to be checked, use radiobuttons with one of them pre-checked. that wouldn’t even need JS.


@Philip: nice quote!

My understanding was that the user must check at least one out of three checkboxes to proceed. But if one only must be checked then radio buttons are obviously the correct approach.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum