View Full Version : Call 2 funtions onSubmit

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:


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:


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";
return true;
return false;

01-30-2007, 10:03 PM
Hi shiftless,

Maybe a silly question as I have not looked at the details, but shouldn't there be something in your action attribute. Usually this would be the script that handles form submission?

<form name="signup" method="post" action="#" onsubmit="OnSubmitCheck(); return false">

01-30-2007, 10:57 PM
yes, i took the action out so i would not inundate my client with test emails. i was wondering if not having an action had any effect on the process. I would think that the redirect page would come up even if the action wasn't going anywhere if it were working properly. anyone?

01-30-2007, 11:07 PM
It won't. A redirect will have to be handled by the script.

Actually your script seem to be working. When you submit the form the page reloads. Notice the # appended to the url in your browsers address line. Because this is the action you specified.

Recall that the page in the action attribute may be any page. It is just tells you the page that is loaded after form submission (just a kind of advanced link), but with the ability to hold post data.

01-31-2007, 12:44 AM
hmmm... this page worked fine when i was only using the script that checks for blank fields. I have a hidden input for the redirect in the form, and that worked fine at that point:

<input type="hidden" value="http://www.clubspaces.com/welcome.htm" name="redirect" />

it's just when i tried incorporating this new email syntax function, the redirect stopped working.

the action sent the post data to a 3rd party service and was not the page that loaded after the form was submitted.

01-31-2007, 01:39 AM
The hidden field merely passes the information about which page the server-side script should redirect you to after it has finished its job handling the data.

Therefore it is still necessary to have the action tag. I think you have misunderstood what forms are doing. For fun you may try to put the redirect page directly into your action tag

<form name="signup" method="post" action="http://www.clubspaces.com/welcome.htm" onsubmit="return (emailCheck(this.email.value) && validate_form())">

It will then look right what is going on seen from the user, but all form handling is bypassed, and the form would be useless.

01-31-2007, 01:58 AM
Well, I added the action back in to test and see if it would send back the redirect, and it didn't work, it just cleared the form. damn this is frustrating...

maybe i should put the redirect in the function?

01-31-2007, 02:11 AM
Alright, there is nothing wrong with your javascript validation.

Where did you get the instructions about what hidden fields to use (names and values)? Try to double check the instructions. It is probably here the problem lies.

01-31-2007, 02:17 AM
OK I have figured it out ( I think). I had at one point changed the hidden input to "redirect" as an experiement, and the 3rd party service requires it to be "retURL" so it's server didn't recognize the info when it was posted. I changed it back and all is working well now. Thanks so much for the help!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum