moneytree Posted April 15, 2008 Share Posted April 15, 2008 Hi everyone, I had tried to set-up the validation function for two webform on my site,however,it didn't work.Please kindly advice what's the caused of it.The following is the two webform code extracted from my home page for your review. <script language="javascript"> function verify() { var errors1 = ""; var errors2 = ""; var errors3 = ""; var message="Please complete the following field(s): \n"; var first = document.myform.firstname.value; var last = document.myform.lastname.value; var email = document.myform.email.value; if (first.length == "0") { errors1="First name\n"; } if (last.length == "0") { errors2="Last name\n"; } if (email.length == "0") { errors3="email address\n"; } if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") { alert(message + "\n\n" + errors1 + errors2 + errors3); } else { document.myform.submit(); } } function verify2() { var errors1 = ""; var errors2 = ""; var errors3 = ""; var message="Please complete the following field(s): \n"; var first = document.myform2.firstname.value; var last = document.myform2.lastname.value; var email = document.myform2.email.value; if (first.length == "0") { errors1="First name\n"; } if (last.length == "0") { errors2="Last name\n"; } if (email.length == "0") { errors3="email address\n"; } if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") { alert(message + "\n\n" + errors1 + errors2 + errors3); } else { document.myform2.submit(); } } </script> --> <!-- First Form --> <form name="myform" METHOD="post" ACTION="http://abc.com/cgi-bin/formmail.pl"> <input type=hidden name="recipient" value="newsletter@abc.com"> <input type=hidden name="subject" value="Thank you for subscribing to newsletter !"> First Name : <input type=text name="firstname" size="20"> Last Name : <input type=text name="lastname" size="20"> Email : <input type=text name="Email" size="20"> <center><input type="submit" value="Yes,I want it !"/></center> </form> <form name="myform2" METHOD="post" ACTION="http://abc.com/cgi-bin/formmail.pl"> <input type=hidden name="recipient" value="ebook@abc.com"> <input type=hidden name="subject" value="Thank you for subscribing to ebook !"> <P align=center>First Name : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" style="BACKGROUND-COLOR: #ffffa0" name=firstname><BR>Last Name : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" style="BACKGROUND-COLOR: #ffffa0" name=lastname><BR>Email : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" style="BACKGROUND-COLOR: #ffffa0" name=email><BR></P> <CENTER><INPUT type=button value="Yes,I want the private access now !" onclick="verify2"></CENTER> </form> Many thanks for your time and efforts in helping me to solve this issue. Best regards manicui Quote Link to comment Share on other sites More sharing options...
zenag Posted April 16, 2008 Share Posted April 16, 2008 now it works... open & close brackets while calling function onclick="verify1()" <html><head><script language="javascript"> function verify1() { var errors1 = ""; var errors2 = ""; var errors3 = ""; var message="Please complete the following field(s): \n"; var first = document.myform2.firstname.value; var last = document.myform2.lastname.value; var email = document.myform2.email.value; if (first.length == "0") { errors1="First name\n"; } if (last.length == "0") { errors2="Last name\n"; } if (email.length == "0") { errors3="email address\n"; } if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") { alert(message + "\n\n" + errors1 + errors2 + errors3); } else { document.myform2.submit(); } } function verify2() { var errors1 = ""; var errors2 = ""; var errors3 = ""; var message="Please complete the following field(s): \n"; var first = document.myform2.firstname.value; var last = document.myform2.lastname.value; var email = document.myform2.email.value; if (first.length == "0") { errors1="First name\n"; } if (last.length == "0") { errors2="Last name\n"; } if (email.length == "0") { errors3="email address\n"; } if (errors1.length >= "1" || errors2.length >= "1" || errors3.length >= "1") { alert(message + "\n\n" + errors1 + errors2 + errors3); } else { document.myform2.submit(); } } </script> </head> <body> <form name="myform" METHOD="post" ACTION=""> <input type=hidden name="recipient" value="newsletter@abc.com"> <input type=hidden name="subject" value="Thank you for subscribing to newsletter !"> First Name : <input type=text name="firstname" size="20"> Last Name : <input type=text name="lastname" size="20"> Email : <input type=text name="Email" size="20"> <center><input type="submit" onClick="verify1()" value="Yes,I want it !"/></center> </form> <form name="myform2" METHOD="post" ACTION=""> <input type=hidden name="recipient" value="ebook@abc.com"> <input type=hidden name="subject" value="Thank you for subscribing to ebook !"> <P align=center>First Name : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" style="BACKGROUND-COLOR: #ffffa0" name=firstname><BR>Last Name : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" style="BACKGROUND-COLOR: #ffffa0" name=lastname><BR>Email : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" style="BACKGROUND-COLOR: #ffffa0" name=email><BR></P> <CENTER><INPUT type=button value="Yes,I want the private access now !" onclick="verify2()"></CENTER> </form> </body></html> Quote Link to comment Share on other sites More sharing options...
moneytree Posted April 21, 2008 Author Share Posted April 21, 2008 Hi zenag, Many thanks for your replied to my query over script's issue. My webform is working now based on your advice for the changes ! Thank you for your time and efforts in helping me. Best regards manicui 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.