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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript validation problem

    I have an issue with a form I am creating, I have many check boxs where at least one of the 2 needs to be selected and the final one has to be selected for the submit button to become active

    Code:
    <form id="form1" action="#" method="post">
    
    One <input type="checkbox" name="value1" onMouseDown='submit_form()'/>
    Two<input type="checkbox" name="value2" onMouseDown='submit_form()'/>
    //atleast 1 of these 2 has to be selected
    
    Three<input type="checkbox" name="value3" onMouseDown='submit_form()'/>
    //this 1 has to be selected
    
    <input type="submit" name="submit" value="submit" id="submit" disabled="disabled"/>

    this is the javascript I have atm to do this

    Code:
    function submit_form(){
    	if (form1.value1.checked == false || form1.value2.checked == false) {
    		document.getElementById(submit);
    		orderForm.submit.disabled=false;
    	}
    }
    i cant seem to get this to work, forgetting about the 3rd checkbox for now

    any help would be greatly appreciated!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    There ain't no such thing as onMouseDown in relation to a checkbox. onclick perhaps?

    if (form1.value1.checked == false && form1.value2.checked == false) {
    alert ("You must check one of the two checkboxes to proceed");
    return false;
    }
    if (form1.value3.checked == false) {
    alert ("You must check box 3 before you can proceed");
    return false;
    }


    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 03-01-2010 at 07:49 PM.

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thankyou for that, helped solve the problem!


  •  

    Tags for this Thread

    Posting Permissions

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