Search the Community
Showing results for tags 'javascript forms email'.
-
Hi there! I am using: a form in HTML, PHP and then I was trying to use Javascript to validate the email address before it was sent to the next PHP page. The problem is... that even if the email is invalid and the javascript function displays an error message, the page >still< proceeds to the next PHP page (as if everything was fine). However, I >want< it to stay on the same page and allow the user to enter in their email address again (correctly). And not advance to the next PHP page >until< the email address has been successfully validated. Below is my HTML, PHP and Javascript. Could anyone kindly tell me what I'm doing wrong? I'd really appreciate it! Thank you very much!! Andrea ================ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>Ballard Social</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> </HEAD> <BODY BGCOLOR="#ddeae7"> <!---------------------- Sign Up on Email List ----------------------> <P> </P><P> </P><P> </P> <table BORDER="1" ALIGN="CENTER" cellpadding="10" CELLSPACING="0" BORDERCOLOR="#bfc2c1" BGCOLOR="white"> <tr><td WIDTH="355"> <FORM onsubmit='return pValidateForm()' ACTION="pAddEmail_BallardSocial_1_validate.php" METHOD="POST" name='myForm' id='myForm' > <P ALIGN="center"> <STRONG><font color="#4c4f4e" face="arial,verdana" size=2>Sign Up on the Email List</STRONG><BR> <font size=1>You will be notified of the next Ballard Social event</font><BR> <INPUT TYPE="Hidden" NAME="SourcePage" VALUE="SignUp.htm"> <INPUT NAME="Email" TYPE="text" size=28 placeholder="enter your email address"> <INPUT NAME="OK2" TYPE="submit" value="OK"></P> </FORM> </td></tr></table> </BODY> </HTML> <script language='javascript'> function pValidateForm() { var x=document.forms['myForm']['Email'].value; var atpos=x.indexOf('@'); var dotpos=x.lastIndexOf('.'); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert('Not a valid e-mail address'); return false; } } </script>