Results 1 to 3 of 3

Thread: Function stops working with 2nd if statement, works fine without...

  1. #1
    Join Date
    May 2012

    Function stops working with 2nd if statement, works fine without...

    Hey guys, so I'm trying to make a single function that will check to make sure the e-mails in both fields match AND to make sure the e-mail is in proper format. Strangely, with both if statements included the form will return no messages at all. If I comment out the if statement checking for proper format, the if statement to check for matching e-mail works just fine.

    I want this all to be in one function because I'm wanting it to be executed onSubmit with the form. Let me know what you guys think, any help is greatly appreciated:

    <script type="text/javascript">
    	function verifyEmail()
    			var x = document.forms["emailForm"]["enterEmail"].value;
    			var y = document.forms["emailForm"]["confirmation"].value;
    			var atpos = x.indexOf("@");
    			var dotpos = x.lastIndexOf(".");
    				if (x != y) {
    					  var msg = "The email addresses entered do not match, please enter matching email addresses";
    					  document.getElementById("error").innerHTML = msg;
    					  return false;
    				if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 > = x.length) {
    					  var msg = "Improper e-mail format";
    					  document.getElementById("error").innerHTML = msg;
    					  return false;
    				else {
    	<form name="emailForm" onsubmit="return verifyEmail();" method="post">
    		E-Mail Address: <input type="text" name="enterEmail">
    		Confirm E-Mail Address: <input type="text" name="confirmation">
    		<input type="submit" value="Submit"> <span id="error"></span>

  2. #2
    Join Date
    May 2006
    Somewhere behind your screen
    no space needed

    Inline script compilation
    Syntax error at line 15 while loading: expected expression, got '='
    + 2 || dotpos + 2 > = x.length) {
    signature under construction

  3. #3
    Join Date
    Dec 2005


    Although it is not strickly necessary, it always helps when you can decode the logic without a lot of effort:

    	if ( (atpos < 1) || (dotpos < (atpos + 2)) || ((dotpos + 2) >= x.length) ) {

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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