shiftless
01-30-2007, 08:49 PM
Hello, new to the forum. I searched for this and found one relevant thread, but their solution did not work for me.
I am calling 2 functions onSubmit in a form. One check to make sure all fields are filled in, the other checks that the email address syntax is correct. If i call one or the other of these funtions, the form seems to work.
However calling both function in the onSubmit doesn't work. Here's the test page:
http://www.clubspaces.com/signuptest.htm
First I tried this :
onsubmit="return (emailCheck(this.email.value) && validate_form())"
but all that would happen is the form fields would get cleared when you click the submit button.
I also tried writing a new function that checks for false from both the original functions:
function OnSubmitCheck() {
var one = emailCheck(this.email.value);
var two = validate_form();
if((one == false) || (two == false)) {
return false;
}
return true;
}
with this in the form:
onSubmit="OnSubmitCheck()"
This also did not work, and again clears the form without submitting it. It SHOULD go to a thank-you page after submitting and the redirect isn't working. Can any one help sort this out? Here is the code for the 2 original fucntions I am trying to call:
function emailCheck(emailStr) {
// checks if the e-mail address is valid
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var matchArray = emailStr.match(emailPat);
if (matchArray == null) {
alert("Your email address seems incorrect. Please try again (check the '@' and '.'s in the email address)");
return false;
}
// make sure the IP address domain is valid
var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
if (IPArray != null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Your email destination IP address is invalid!");
return false;
}
}
}
return true;
}
function validate_form() {
var message="Please complete the following: \n------------------------------------------------\n";
var noerrors=message;
if (document.getElementById('template').value == "") {
message=message + "Please choose a template for your site! \n";
}
if (document.getElementById('clubtype').value == "") {
message=message + "Please tell us what type of club you have! \n";
}
if (document.signup.company.value == "") {
message=message + "Please choose a name for your club! \n";
}
if (document.signup.first_name.value == "") {
message=message + "Please fill in your first name! \n";
}
if (document.signup.last_name.value == "") {
message=message + "Please fill in your last name! \n";
}
if (document.signup.email.value == "") {
message=message + "You must provide us with an email address! \n";
}
if (document.signup.phone.value == "") {
message=message + "Please fill in your phone number! \n";
}
if (document.signup.city.value == "") {
message=message + "Please fill in your city of residence! \n";
}
if (document.signup.state.value == "") {
message=message + "Please fill in your state of residence! \n";
}
if (document.signup.country.value == "") {
message=message + "Please fill in your country of residence! \n";
}
if (document.getElementById('numbers').value == "") {
message=message + "Please fill in the number of members you have! \n";
}
if (document.getElementById('refer').value == "") {
message=message + "Please tell us how you found us! \n";
}
if (!document.signup.tac.checked){
message=message + "You must agree to the Terms and Conditions before proceeding! \n";
}
if(message==noerrors){
return true;
}
else{
alert(message);
return false;
}
}
I am calling 2 functions onSubmit in a form. One check to make sure all fields are filled in, the other checks that the email address syntax is correct. If i call one or the other of these funtions, the form seems to work.
However calling both function in the onSubmit doesn't work. Here's the test page:
http://www.clubspaces.com/signuptest.htm
First I tried this :
onsubmit="return (emailCheck(this.email.value) && validate_form())"
but all that would happen is the form fields would get cleared when you click the submit button.
I also tried writing a new function that checks for false from both the original functions:
function OnSubmitCheck() {
var one = emailCheck(this.email.value);
var two = validate_form();
if((one == false) || (two == false)) {
return false;
}
return true;
}
with this in the form:
onSubmit="OnSubmitCheck()"
This also did not work, and again clears the form without submitting it. It SHOULD go to a thank-you page after submitting and the redirect isn't working. Can any one help sort this out? Here is the code for the 2 original fucntions I am trying to call:
function emailCheck(emailStr) {
// checks if the e-mail address is valid
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var matchArray = emailStr.match(emailPat);
if (matchArray == null) {
alert("Your email address seems incorrect. Please try again (check the '@' and '.'s in the email address)");
return false;
}
// make sure the IP address domain is valid
var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
if (IPArray != null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Your email destination IP address is invalid!");
return false;
}
}
}
return true;
}
function validate_form() {
var message="Please complete the following: \n------------------------------------------------\n";
var noerrors=message;
if (document.getElementById('template').value == "") {
message=message + "Please choose a template for your site! \n";
}
if (document.getElementById('clubtype').value == "") {
message=message + "Please tell us what type of club you have! \n";
}
if (document.signup.company.value == "") {
message=message + "Please choose a name for your club! \n";
}
if (document.signup.first_name.value == "") {
message=message + "Please fill in your first name! \n";
}
if (document.signup.last_name.value == "") {
message=message + "Please fill in your last name! \n";
}
if (document.signup.email.value == "") {
message=message + "You must provide us with an email address! \n";
}
if (document.signup.phone.value == "") {
message=message + "Please fill in your phone number! \n";
}
if (document.signup.city.value == "") {
message=message + "Please fill in your city of residence! \n";
}
if (document.signup.state.value == "") {
message=message + "Please fill in your state of residence! \n";
}
if (document.signup.country.value == "") {
message=message + "Please fill in your country of residence! \n";
}
if (document.getElementById('numbers').value == "") {
message=message + "Please fill in the number of members you have! \n";
}
if (document.getElementById('refer').value == "") {
message=message + "Please tell us how you found us! \n";
}
if (!document.signup.tac.checked){
message=message + "You must agree to the Terms and Conditions before proceeding! \n";
}
if(message==noerrors){
return true;
}
else{
alert(message);
return false;
}
}