Sawtooth500
03-23-2009, 02:49 AM
Reference:
http://tarashryniw.com/noahscs/property_management.php
So there are two forms on this page, and I'm using Javascript validation. The first validation works fine. The second form however (function validateform2), well it crashes between alert("test1") and alert("test2"). What am I doing wrong on that line?
function isavalidemail(inputValue) {
var foundAt = false
var foundDot = false
for (var i=0; i<=inputValue.length; i++) {
if (inputValue.charAt(i) == "@" ) {
foundAt = true
}
else if (inputValue.charAt(i) == ".") {
foundDot = true
}
}
if (foundAt && foundDot) {
return true
}
else {
return false
}
}
function exists(inputValue) {
var aCharExists = false
for (var i=0; i<=inputValue.length; i++) {
if (inputValue.charAt(i) != " " && inputValue.charAt(i) != "") {
aCharExists = true
break
}
}
return aCharExists
}
function isavalidphonenumber(inputValue) {
var stripped = inputValue.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
return false;
}
if (!(stripped.length == 10 || (stripped.length == 11 && stripped[0] == '1'))) {
return false;
}
return true;
}
function validateform(){
var name = exists(document.investment_form.Name.value);
var phone = exists(document.investment_form.Phone.value);
var email = exists(document.investment_form.Email.value);
var validphone = false;
var validemail = false;
if(phone) validphone = isavalidphonenumber(document.investment_form.Phone.value);
if(email) validemail = isavalidemail(document.investment_form.Email.value);
if(name && validphone && validemail) return true;
var badname = "-No name.\n";
var nophone = "-No telephone number.\n";
var noemail = "-No email address.\n";
var invalidphone = "-Telephone invalid. Please make sure that your telephone number has only 10 or 11 digits - no more, no less. Any combination of parentheses, dashes, or spaces may be used. Also, if you entered an 11 digit telephone number make sure it begins with \"1\".\n";
var invalidemail = "-Invalid Email. Please enter a valid email address.\n";
var alertline = "The following problems were encountered with your submission:\n\n";
if(!name) alertline += badname;
if(!email) alertline += noemail;
else if(!validemail) alertline += invalidemail;
if(!phone) alertline += nophone;
else if(!validphone) alertline += invalidphone;
alertline += "\nPlease make corrections and submit again. Thank you.";
alert(alertline);
return false;
}
function validateform2(){
alert("test1");
var name2 = exists(document.residential_form.Name.value);
alert("test2");
var phone2 = exists(document.residential_form.Phone.value);
var email2 = exists(document.residential_form.Email.value);
var validphone2 = false;
var validemail2 = false;
if(phone2) validphone2 = isavalidphonenumber(document.residential_form.Phone.value);
if(email2) validemail2 = isavalidemail(document.residential_form.Email.value);
if(name2 && validphone2 && validemail2) return true;
var badname2 = "-No name.\n";
var nophone2 = "-No telephone number.\n";
var noemail2 = "-No email address.\n";
var invalidphone2 = "-Telephone invalid. Please make sure that your telephone number has only 10 or 11 digits - no more, no less. Any combination of parentheses, dashes, or spaces may be used. Also, if you entered an 11 digit telephone number make sure it begins with \"1\".\n";
var invalidemail2 = "-Invalid Email. Please enter a valid email address.\n";
var alertline2 = "The following problems were encountered with your submission:\n\n";
if(!name2) alertline2 += badname2;
if(!email2) alertline2 += noemail2;
else if(!validemail2) alertline2 += invalidemail2;
if(!phone2) alertline2 += nophone2;
else if(!validphone2) alertline2 += invalidphone2;
alertline2 += "\nPlease make corrections and submit again. Thank you.";
alert(alertline2);
return false;
}
http://tarashryniw.com/noahscs/property_management.php
So there are two forms on this page, and I'm using Javascript validation. The first validation works fine. The second form however (function validateform2), well it crashes between alert("test1") and alert("test2"). What am I doing wrong on that line?
function isavalidemail(inputValue) {
var foundAt = false
var foundDot = false
for (var i=0; i<=inputValue.length; i++) {
if (inputValue.charAt(i) == "@" ) {
foundAt = true
}
else if (inputValue.charAt(i) == ".") {
foundDot = true
}
}
if (foundAt && foundDot) {
return true
}
else {
return false
}
}
function exists(inputValue) {
var aCharExists = false
for (var i=0; i<=inputValue.length; i++) {
if (inputValue.charAt(i) != " " && inputValue.charAt(i) != "") {
aCharExists = true
break
}
}
return aCharExists
}
function isavalidphonenumber(inputValue) {
var stripped = inputValue.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
return false;
}
if (!(stripped.length == 10 || (stripped.length == 11 && stripped[0] == '1'))) {
return false;
}
return true;
}
function validateform(){
var name = exists(document.investment_form.Name.value);
var phone = exists(document.investment_form.Phone.value);
var email = exists(document.investment_form.Email.value);
var validphone = false;
var validemail = false;
if(phone) validphone = isavalidphonenumber(document.investment_form.Phone.value);
if(email) validemail = isavalidemail(document.investment_form.Email.value);
if(name && validphone && validemail) return true;
var badname = "-No name.\n";
var nophone = "-No telephone number.\n";
var noemail = "-No email address.\n";
var invalidphone = "-Telephone invalid. Please make sure that your telephone number has only 10 or 11 digits - no more, no less. Any combination of parentheses, dashes, or spaces may be used. Also, if you entered an 11 digit telephone number make sure it begins with \"1\".\n";
var invalidemail = "-Invalid Email. Please enter a valid email address.\n";
var alertline = "The following problems were encountered with your submission:\n\n";
if(!name) alertline += badname;
if(!email) alertline += noemail;
else if(!validemail) alertline += invalidemail;
if(!phone) alertline += nophone;
else if(!validphone) alertline += invalidphone;
alertline += "\nPlease make corrections and submit again. Thank you.";
alert(alertline);
return false;
}
function validateform2(){
alert("test1");
var name2 = exists(document.residential_form.Name.value);
alert("test2");
var phone2 = exists(document.residential_form.Phone.value);
var email2 = exists(document.residential_form.Email.value);
var validphone2 = false;
var validemail2 = false;
if(phone2) validphone2 = isavalidphonenumber(document.residential_form.Phone.value);
if(email2) validemail2 = isavalidemail(document.residential_form.Email.value);
if(name2 && validphone2 && validemail2) return true;
var badname2 = "-No name.\n";
var nophone2 = "-No telephone number.\n";
var noemail2 = "-No email address.\n";
var invalidphone2 = "-Telephone invalid. Please make sure that your telephone number has only 10 or 11 digits - no more, no less. Any combination of parentheses, dashes, or spaces may be used. Also, if you entered an 11 digit telephone number make sure it begins with \"1\".\n";
var invalidemail2 = "-Invalid Email. Please enter a valid email address.\n";
var alertline2 = "The following problems were encountered with your submission:\n\n";
if(!name2) alertline2 += badname2;
if(!email2) alertline2 += noemail2;
else if(!validemail2) alertline2 += invalidemail2;
if(!phone2) alertline2 += nophone2;
else if(!validphone2) alertline2 += invalidphone2;
alertline2 += "\nPlease make corrections and submit again. Thank you.";
alert(alertline2);
return false;
}