cluce Posted May 9, 2007 Share Posted May 9, 2007 I am trying to validate for required feilds and for identical passwords but the form still gets submitted. When I hit OK the message comes up saying that the fields are required but it still submits the info. after I click OK to the message. I cant see why this happening. Can anybody tell me whats wrong with my code? <!-- TemplateEndEditable --> <style type="text/css"> <!-- body { background-image: url(images/bg_tile.gif); } .style8 {font-size: 12px} a:visited { color: #000000; text-decoration: none; } a:hover { color: #FF6600; background-color: #999999; text-decoration: underline; } a:link { color: #000000; text-decoration: none; } a:active { color: #FF6600; text-decoration: none; } .style12 {font-size: 14px} .style14 {color: #FF0000} .style15 {font-family: "Times New Roman", Times, serif; font-size: 14px; color: #FF0000; } .style16 { font-size: 18px; font-family: "Times New Roman", Times, serif; font-weight: bold; } --> </style> <!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable --> <script type="text/JavaScript"> <!-- function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_validateForm() { //v4.0 var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } //--> </script> <div align="center"> <table width="852" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="852" height="85" colspan="2" align="left" valign="middle" background="images/BG1.png" bgcolor="#CCCCCC" scope="col"><div align="center"> <p><img src="images/reagman_L.gif" alt="Reagan logo" width="99" height="98" /><img name="ReaganPower" src="images/Reagan Power.gif" width="581" height="59" border="0" id="ReaganPower" alt="Reagan logo" /><img src="images/reagman_R.gif" alt="Reagan logo" width="99" height="98" /></p> </div> <div align="center"></div></th> </tr> <tr> <td colspan="2" align="left" valign="top" bgcolor="#FFFFFF"><p> </p> <blockquote> <p align="center" class="style16">Registration Form </p> <p align="center" class="style15">If you are a first time user, you must register </p> </blockquote> <script type="text/javascript" language="JavaScript"> <!-- function BothFieldsIdentical() { var one = document.form1.password.value; var another = document.form1.confirmpassword.value; if(one != another) { alert("Passwords must be identical."); return false; } } //--> </script> <form id="form1" name="form1" method="post" action="insert.php"> <blockquote> <blockquote> <blockquote> <p align="center" class="style12">Fields marked with <span class="style14">*</span> are required. </p> </blockquote> </blockquote> </blockquote> <table width="426" border="0" align="center" cellpadding="1" cellspacing="1"> <tr> <td width="165"><div align="left">Username</div></td> <td width="278"><input name="username" type="text" id="username" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td>Password</td> <td><input name="password" type="password" id="password" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td>Confirm Password </td> <td><input name="confirmpassword" type="password" id="confirmpassword" size="30" /> <span class="style14"> *</span></td> </tr> <tr> <td>First Name: </td> <td><input name="firstname" type="text" id="firstname" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">Middle:</div></td> <td><input name="middle" type="text" id="middle" size="30" /></td> </tr> <tr> <td><div align="left">Last Name: </div></td> <td><input name="lastname" type="text" id="lastname" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">Address:</div></td> <td><input name="address" type="text" id="address" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">City:</div></td> <td><input name="city" type="text" id="city" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">State:</div></td> <td><input name="state" type="text" id="state" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">Zip:</div></td> <td><input name="zip" type="text" id="zip" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">Phone number:</div></td> <td><input name="phone" type="text" id="phone" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">Alternate Phone number: </div></td> <td><input name="alternate" type="text" id="alternate" size="30" /></td> </tr> <tr> <td><div align="left">Email:</div></td> <td><input name="email" type="text" id="email" size="30" /> <span class="style14">*</span></td> </tr> <tr> <td><div align="left">Company:</div></td> <td><input name="company" type="text" id="company" size="30" /></td> </tr> </table> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <p align="left"> </p> </blockquote> </blockquote> </blockquote> </blockquote> <p align="center"> <input name="Submit" type="submit" onclick="MM_validateForm('username','','R','firstname','','R','lastname','','R','address','','R','city','','R','state','','R','zip','','R','phone','','R','email','','RisEmail','password','','R','confirmpassword','','R');return BothFieldsIdentical();return document.MM_returnValue" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></p> <p align="center"> </p> </blockquote> </form> </td> </tr> <tr> <td colspan="2" background="images/BG1.png" bgcolor="#CCCCCC"><div align="center"><span class="style8"><strong>Reagan Equipment Co., Inc.</strong><br /> Toll free: 800.264.7767<br /> Email: <a href="mailto:info@reaganpower.com">info@reaganpower.com</a></span></div></td> </tr> <tr> <td colspan="2" background="images/BG1.png" bgcolor="#CCCCCC"><div align="center"> <p class="style8">Copyright © 2007<br /> <a href="http://www.point2pointhosting.com/" class="style12"> Hosted by point2point</a></p> </div></td> </tr> </table> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
fenway Posted May 9, 2007 Share Posted May 9, 2007 You have too many returns in the onclick handler -- and you don't have an onsubmit handler either. Quote Link to comment Share on other sites More sharing options...
cluce Posted May 9, 2007 Author Share Posted May 9, 2007 if you dont mind me asking, how do I fix that? I used Dreamweaver to create one function and the Bothfieldsidentical function I created. I have the same functions used on a small form of two fields that works but with this one with several fields it doesn't work. Quote Link to comment Share on other sites More sharing options...
fenway Posted May 9, 2007 Share Posted May 9, 2007 Only the first return will be respected, since the second one will never run. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.