Hi, I am thinking of keeping a contact/feedback form on my website and am in search of a validation code for the sections. I have found an e-mail validation at w3schools but since i am a complete noob at javascript, i am unable to expand it to other sections. If anybody can tell me where can i find the codes, or even examples of how to expand it, i will be pretty grateful
Designcode, thanks for your help..here's the code <html> <head> <title>Contact Form</title> </head> <body> <form action="http://www.yoursitename.com/cgi-sys/formmail.pl" name="myform" > <input type="hidden" name="recipient" value="email"> <input type="hidden" name="subject" value="FormMail E-Mail"> <table cellspacing="2" cellpadding="2" border="0"> <tr> <td align="left">Name: <input type="text" name="Name" size="50"></td> </tr> <tr> <td align="left">EMail: <input type="text" name="Email" size="50"></td> </tr> <tr> <td align="left">Feedback</td></tr> <tr> <td><textarea cols="50" rows="10" name="Feedback"></textarea></td> </tr> <tr> <td align="left"> <input type="submit" value="Submit"><input type="reset" value="Reset"> <input type="hidden" name="redirect" value="thankyou.html"></td> </tr> </table> </form>
Here is your code with JS validation <html> <head> <title>Contact Form</title> </head> <body> <script type="text/javascript"> function validateForm() { var f = document.myform; if(f.Name.value == "") { alert("Please enter your name"); f.Name.focus(); return false; } else if(!checkEmail(f.Email.value)) { alert("Please enter your email address"); f.Email.focus(); return false; } else if(f.Feedback.value == "") { alert("Please enter some message"); f.Feedback.focus(); return false; } } function checkEmail(str) { // Function from SmartWebby.com, modified by designcode if(str == "") return; var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1) return false; if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false; if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false; if (str.indexOf(at,(lat+1))!=-1) return false; if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false; if (str.indexOf(dot,(lat+2))==-1) return false; if (str.indexOf(" ")!=-1) return false; return true; } </script> <form action="http://www.yoursitename.com/cgi-sys/formmail.pl" onsubmit="return validateForm();" name="myform" > <input type="hidden" name="recipient" value="email"> <input type="hidden" name="subject" value="FormMail E-Mail"> <table cellspacing="2" cellpadding="2" border="0"> <tr> <td align="left">Name: <input type="text" name="Name" size="50"></td> </tr> <tr> <td align="left">EMail: <input type="text" name="Email" size="50"></td> </tr> <tr> <td align="left">Feedback</td></tr> <tr> <td><textarea cols="50" rows="10" name="Feedback"></textarea></td> </tr> <tr> <td align="left"> <input type="submit" value="Submit"><input type="reset" value="Reset"> <input type="hidden" name="redirect" value="thankyou.html"></td> </tr> </table> </form> Code (markup):