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 regardsmanicui Link to comment Share on other sites More sharing options...
Ingolme Posted April 15, 2008 Share Posted April 15, 2008 This code looks so old fashioned. Have you tried passing the HTML through The Validator?And I really doubt the cross-browser compatibility of document.myform.firstname.value.Give each of your input elements an ID attribute and access them with document.getElementById("ID")For example:<input name="firstname" type="text" id="Fname"> <!-- accessible with document.getElementById("Fname").value -->About scripting errors:This is supposed to be a numerical value:if(first.length == "0")So remove the quotes:if(first.length == 0)And this could be much more simplified like this: var errors = "";if (first.length == 0) errors+="First name\n";if (last.length == "0") errors+="Last name\n";if (email.length == "0") errors+="email address\n";if (errorslength > 0) {alert(message + "\n\n" + errors1 + errors2 + errors3);} else {/*Create your form like this:<form action="something" method="post" id="Form">*/document.getElementById("Form").submit();} Link to comment Share on other sites More sharing options...
moneytree Posted April 16, 2008 Author Share Posted April 16, 2008 Hi Ingolme,Many thanks for your kind responsed to my query over webform issue.There're two webform on my site and both failed to validate the firstname,lastname and email address,it even allowed to submit the opt-in simply by clicking on the submit button.I had tried to made some changes,but,it failed to work.The drop-down webform seems a bit confussing,when you clicked on submit button,it did show the pop-up validation box,but when you clicked on ok button of the pop-up,it submitted the opt-in by itself !Please kindly review and advice the caused to it at my site www.moneymakeyourich.comThank you for your time and efforts in helping me.Best regardsmanicui Link to comment Share on other sites More sharing options...
Ingolme Posted April 16, 2008 Share Posted April 16, 2008 The javascript code on your site is just the same as before.You haven't fixed anything. Do as I said in my previous post and it should work just fine. Link to comment Share on other sites More sharing options...
moneytree Posted April 16, 2008 Author Share Posted April 16, 2008 Hi Ingolme,It's really nice to hear from you again over my webform issue.1 ) I had run through my script for the following advice,but,can't find it.May I know where's it ?About scripting errors:This is supposed to be a numerical value:if(first.length == "0")So remove the quotes:if(first.length == 0)2 ) I had tried to followed your advice to made some changes as follow,please kindly review and advice on it.<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 name="firstname" type="text" id="Fname" size="20"> Last Name :<input name="lastname" type="text" id="lname" size="20"> Email :<input type=text name="Email" size="20"><center><input name="submit" type="text" id="submit" value="Yes,I want it ! onclick="verify()"/></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" id="fname"><BR>Last Name : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill" style="BACKGROUND-COLOR: #ffffa0" name="lastname" id="lname"><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 name="submit" type="text" id="submit" value="Yes,I want the private access now !" onclick="verify2()"/></CENTER></form>Many thanks for your time and efforts in helping me.Best regardsmanicui Link to comment Share on other sites More sharing options...
Ingolme Posted April 16, 2008 Share Posted April 16, 2008 OK, here it is all done for you: <script type="text/javascript"><!-- Converted to valid HTML -->function verify() { var errors = ""; // Created a common error message variable var message="Please complete the following field(s): \n"; var first = document.getElementById("Fname").value; //Access element by ID var last = document.getElementById("Lname").value; //Access element by ID var email = document.getElementById("Mail").value; //Access element by ID if (first.length == 0) { //Removed quotes from "0" -> 0 errors+="First name\n"; //Added to error message } if (last.length == 0) { //Removed quotes from "0" -> 0 errors+="Last name\n"; //Added to error message } if (email.length == 0) { //Removed quotes from "0" -> 0 errors+="email address\n"; //Added to error message } if (errors.length > 0) { //Removed quotes from numberical values. Simplified logical expression alert(message + "\n\n" + errors); //Removed redundant variables } else { document.getElementById("Form").submit(); }}function verify2() {var errors = ""; // Created a common error message variablevar message="Please complete the following field(s): \n";var first = document.getElementById("Name").value;var last = document.getElementById("Last").value;var email = document.getElementById("Email").value; if (first.length == 0) { //Removed quotes from "0" -> 0 errors+="First name\n"; //Added to error message } if (last.length == 0) { //Removed quotes from "0" -> 0 errors+="Last name\n"; //Added to error message } if (email.length == 0) { //Removed quotes from "0" -> 0 errors+="email address\n"; //Added to error message } if (errors.length > 0) { //Removed quotes from numberical values. Simplified logical expression alert(message + "\n\n" + errors); //Removed redundant variables } else { document.getElementById("nextForm").submit(); }}</script><!-- First Form --><form id="Form" METHOD="post" ACTION="http://abc.com/cgi-bin/formmail.pl"><input type="hidden" name="recipient" value="newsletter@abc.com"><!-- converted to valid HTML --><input type="hidden" name="subject" value="Thank you for subscribing to newsletter !"><!-- converted to valid HTML -->First Name :<input name="firstname" type="text" id="Fname" size="20">Last Name :<input name="lastname" type="text" id="Lname" size="20">Email :<input type="text" name="Email" id="Mail" size="20"><!-- converted to valid HTML. Added ID attribute --><center><!-- Changed type from "submit" to "button" --><input name="button" type="text" value="Yes,I want it!" onclick="verify()"/></center></form><form id="nextForm" 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" id="Name"><BR>Last Name :<INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill"style="BACKGROUND-COLOR: #ffffa0"name="lastname" id="Last"><BR>Email : <INPUT title="Your Google Toolbar can fill this in for you. Select AutoFill"style="BACKGROUND-COLOR: #ffffa0" name="email"><BR></P><CENTER><!-- Converted from type "text" to "button" --><input type="button" value="Yes,I want the private access now !" onclick="verify2()"/></CENTER></form> Link to comment Share on other sites More sharing options...
jeffman Posted April 16, 2008 Share Posted April 16, 2008 OK, here it is all done for you:Above and beyond the call of duty, Ingolme. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 16, 2008 Share Posted April 16, 2008 Now what did you learn from this moneytree? Link to comment Share on other sites More sharing options...
moneytree Posted April 19, 2008 Author Share Posted April 19, 2008 Hi Ingolme,Deirdre's Dad,justsomeguy,It's really nice to have you guy in this forum to help newbie like me to solve their scripts' problem.It allowed me to proceed further to promote my site after receiving your constructive solution to my script's problem.Many thanks for your time and efforts in helping me.Best regardsmanicui Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.