Results 1 to 2 of 2

Thread: Javascript form validation help

  1. #1
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript form validation help

    I am 95% there, but since I am not a Javascript or web developer by trade, I couldn't beat this into submission. Any help would be greatly appreciated.

    I have this simple script that evaluates text input fields and a checkbox that someone must check before proceeding. "agreement" is the checkbox name/id. I have this working without any problems when I use text fields but when I introduce the checkbox it does not seem to work.

    Any help is greatly appreciated! Thanks in advance.
    Code:
    <form onsubmit="return checkForm(this)">
    <input name="agreement" type="checkbox" id="agreement" value="1" />
    ...
    </form>
    
    <script type="text/javascript"> 
    function checkForm(frm){ 
    msg = ""; 
       
    if(!frm.first_name.value){ 
          msg += "- First name is required\n"; 
       } 
    
     if(!frm.agreement.value){ 
          msg += "- Accept the terms of use\n";
    	     
       } 
    
    if(msg != ""){ 
          alert(msg); 
          return false;
     } 
    } 
    </script>

  2. #2
    Join Date
    Oct 2008
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    From my understanding, you would just like to make this 'required' before processing? Is this just a simple e-mail form?

    http://www.elated.com/articles/form-...th-javascript/
    Last edited by trochia; 02-21-2009 at 02:08 PM. Reason: add url

Bookmarks

Posting Permissions

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