Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Issue with Validation code

    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
    Code:
    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
    Code:
    vald +=  validateEmpty(frm.Description0) && "-Incident or Task Description:\n";
    		vald +=  validateEmpty(frm.duias) && "-Discussed urgency/impact/assigned severity?\n";

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    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

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    dslegends (10-30-2012)

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,474
    Thanks
    13
    Thanked 361 Times in 357 Posts
    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!
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by Dormilich View Post
    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.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •