Nov 4, 2004 #1 techskool Technical User Jun 20, 2002 151 GB Hi Guys I have to validate for form input. I have a form with 4 textboxes, and i need to check onSubmit that at least one of the four fields has been filled out. How do i do this please? Many Thanks Dave
Hi Guys I have to validate for form input. I have a form with 4 textboxes, and i need to check onSubmit that at least one of the four fields has been filled out. How do i do this please? Many Thanks Dave
Nov 4, 2004 #2 prrm333 Programmer Apr 14, 2003 97 US This is the basics of how to do it. You can expand it from here: In the <head> section: <script language="JavaScript" type="text/javascript"> function validateForm() { val1 = document.frmName.text1.value; val2 = document.frmName.text2.value; val3 = document.frmName.text3.value; val4 = document.frmName.text4.value; if (val1.length == 0 && val2.length == 0 && val3.length == 0 && val4.length == 0) { alert("Enter your error message here."); document.frmName.text1.focus(); return false; } } </script> In the <body> section: <form action="okayPage.html" method="post" name="frmName" onSubmit="return validateForm();"> <input type="text" width="20" name="text1"><br> <input type="text" width="20" name="text2"><br> <input type="text" width="20" name="text3"><br> <input type="text" width="20" name="text4"><br> <input type="submit" value="submit"> </form> Upvote 0 Downvote
This is the basics of how to do it. You can expand it from here: In the <head> section: <script language="JavaScript" type="text/javascript"> function validateForm() { val1 = document.frmName.text1.value; val2 = document.frmName.text2.value; val3 = document.frmName.text3.value; val4 = document.frmName.text4.value; if (val1.length == 0 && val2.length == 0 && val3.length == 0 && val4.length == 0) { alert("Enter your error message here."); document.frmName.text1.focus(); return false; } } </script> In the <body> section: <form action="okayPage.html" method="post" name="frmName" onSubmit="return validateForm();"> <input type="text" width="20" name="text1"><br> <input type="text" width="20" name="text2"><br> <input type="text" width="20" name="text3"><br> <input type="text" width="20" name="text4"><br> <input type="submit" value="submit"> </form>
Nov 4, 2004 Thread starter #3 techskool Technical User Jun 20, 2002 151 GB Thats fantastic my friend Dave Upvote 0 Downvote