1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.
  2. Better Analytics for WordPress Get It Free

Need help with some javascript form validation.

Discussion in 'JavaScript' started by adriankoss, Nov 22, 2008.

  1. #1
    I am missing something here does anyone know where i am going wrong?

    This is the javascript. Its linked in the head of the doc.
    
    function vailidate_form (){
    
    	vaild = true;
    	
    var error = "mail_list" ;
    var tfld = trim(document.mail_list.mail_inp) ;
    var emailfilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalchars = /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    	
    	if ( document.mail_list.mail_inp.value =="" )
    	{
    		alert ("Please fill in the damn form");
    		vaild = false;
    	}else if (!emailfilter.test(tfld)) {
    		alert ("Please use the right syntex email@email.com");
    		vaild = false;
    	}else if (document.mail_list.mail_inp.value.match(illegalchars)){
    		alert ("Sorry there has been a error, Please retype your email")
    		vaild = false;
    	}
    	
    	return error;
    }
    
    Code (markup):
    This is the form.
    
    <div id="mail">
           <div id="bar">
              <img src="img/mailback.png" alt="" />
           </div>
    <form id="mailinglist" name="mail_list" method="post" onsubmit="return validate_form();" action="mailform.php">
    <label for="mailinp"></label>
    <input id="mailinp" name="mail_inp" type="text" />
    <input class="mailsub" type="submit" value="Send" />
    </form>
    </div>
    
    Code (markup):
    Thanks any help would be appreciated .
     
    adriankoss, Nov 22, 2008 IP
  2. BrandonGregory

    BrandonGregory Peon

    Messages:
    28
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you need to change that last line to:

    if (!vaild) return false;
    else return true;
    Code (markup):
     
    BrandonGregory, Nov 24, 2008 IP
  3. GreatMetro

    GreatMetro Peon

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Look at the typo in your function declaration for a start:

    function vailidate_form (){
     
    GreatMetro, Nov 24, 2008 IP
  4. adriankoss

    adriankoss Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks i am still new to all this. I tried both of the ideas still no luck. Here is what I have now.
    
    function vailidate_form ()
    {
    
    	vaild = true;
    	
    var error = "" ;
    var tfld = trim(nav.mail.mail_list.mail_inp) ;
    var emailfilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalchars = /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    	
    	if ( tfld.value =="" )
    	{
    		alert ("Please fill in the damn form");
    		vaild = false;
    	}else if (!emailfilter.test(tfld)) {
    		alert ("Please use the right syntex email@email.com");
    		vaild = false;
    	}else if (tfld.value.match(illegalchars)) {
    		alert ("Sorry there has been a error, Please retype your email")
    		vaild = false;
    	}
    	
    	if (!vaild) return false;
    	else return true;
    }
    
    Code (markup):
    
    <div id="mail">
        <div id="bar">
    	<img src="img/mailback.png" alt="" />
         </div>
      <form id="mailinglist" name="mail_list" method="post" onsubmit="return validate_form();" action="mailform.php">
      <label for="mailinp"></label>
      <input id="mailinp" name="mail_inp" type="text" />
      <input class="mailsub" type="submit" value="Send" />
      </form>
    </div>
    
    Code (markup):
     
    adriankoss, Nov 25, 2008 IP
  5. GreatMetro

    GreatMetro Peon

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Still have a typo. You're calling:

    onsubmit="return validate_form();"

    but your function declaration is:

    function vailidate_form ()


    See the typo? :rolleyes:
     
    GreatMetro, Dec 13, 2008 IP
  6. adriankoss

    adriankoss Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for the help i think i may have been doing things a bit to fast. Thanks again.
     
    adriankoss, Feb 2, 2009 IP