PDA

View Full Version : JavaScript: Combined functions not working


Juparis
08-14-2004, 09:27 PM
I have a sign-up page on my website with which I'm trying to add several JavaScript functions. I posted about this before, but I got no response. I've looked across the net and fixed up the code as much I could, but all my attempts seem to be futile. With all of the functions, not a single one works on the form. Hopefulle, with as far as I've fixed it up, someone can find what I've done wrong...

Script:
<script type="text/javascript">
<!-- Begin

var formerrormsg="Please Wait...\n You've already submitted the form once."

function checksubmit(submitbtn)
{
submitbtn.form.submit();
checksubmit = blocksubmit;
return false;
}

function blocksubmit()
{
if (typeof formerrormsg!="undefined")
{
alert(formerrormsg);
}
return false;
}

function ComparePassword(one,two)
{
one = form.Password.value;
two = form.PasswordConfirm.value;
if (one == two)
{
return true;
}
else
{
alert ("I'm sorry, you did not correctly fill out this form. Please make sure your passwords match.");
return false;
}
}

function CompareEmail(one,two)
{
one = form.Email.value;
two = form.EmailConfirm.value;
if (one == two)
{
return true;
}
else
{
alert ("I'm sorry, you did not correctly fill out this form. Please make sure your emails match.");
return false;
}
}

function validateForm()
{
for(i=0;i<=4;i++)
{
if(document.UD.elements[i].value=="")
{
var count=1;
var msg=msg+"\n"+document.UD.elements[i].name;
}
else if((i>3) && (count==0))
{
return(true);
}
}
for(i=0;i<=4;i++)
{
if(document.UD.elements[i].value=="")
{
alert("PLEASE FILL IN THE FOLLOWING FIELD(S)\n "+msg);
document.UD.elements[i].focus();
return(false);
}
}
}
function checkEmail(myForm)
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.Email.value))
{
return (true);
}
else
{
alert("Invalid E-mail Address! Please re-enter.");
return (false);
}
}
// End -->
</script>

Form tag: (could this be it?)
<form METHOD="POST" NAME="myForm"
ACTION="http://www.qkxyq.com/thalasson/mailform.cgi" onsubmit="return check(this) && checkPw(this) && checkEm(this) && return validateForm(this) && return checkEmail(this)">

The cgi file is to mail the information to me. Someone had suggested that I nest the CGI into the script, but I don't know what the script is. I'm using it off of a site for free, and have no clue what it could possibly contain. Despite that fact and the fact that I've never used CGI before, I tried it. I got a free script and tried to manipulate it to my needs. Sadly, my web host didn't have the proper preloaded scripts and it only complicated everything even more. So please, don't ask me about any CGI; I've been there and failed once. Let's not make it twice...

I appreciate all help and suggestions! Thanks!

n8thegreat
08-15-2004, 04:47 PM
you cant do return something && something && something.
you can only return one value in a return statement (note: this can be an array)
you need to do something like return checkAll(this), where checkALL is a function that calls all the other functions and if anyone is false, return false.

Juparis
08-17-2004, 01:04 PM
aHA! Thanks for your help!

I'm still blind when it comes to JavaScript, so how would I make such a function?