Click to See Complete Forum and Search --> : validation errors


rdharris
02-06-2003, 09:44 AM
Here is the code for verifying 3 fields in a form.
[e.g: "You must fill in your name to continue" alert]

I've been getting help on this, but there is still some
problems. As it is now, if the verification fails, an alert
pops up successfully. However one has to click ok twice
for some reason?? The page is successfully remaining
in the "form" page. (didn't before) Now when all the fields
are correct, it's not going to the "mail.asp" page..
(the "thank you.." page.)

Also, when the form was sending, I would receive
two emails instead of one, though the code has
changed a bit since that, so I'm not sure if that
problem still exists.


I'm sure this is an likely easy fix, but I can't
get it to work..

Thank any and all !

rob


here is the JavaScript:

********************************
function RequiredFields()
{
if( Validate() )
{
// validation passed, allow post
document.frmInfo.txtAction.value = "Submit";
return true;
} // validation failed, disallow post return false;
}


function Validate()
{


//--- Make sure the Name was entered
if(document.frmInfo.txtName.value.length == 0){
document.frmInfo.txtName.focus();
document.frmInfo.txtName.select();
alert("You must enter your name to continue.");
return false;
}
//--- Make sure the EMail Address was entered
if(document.frmInfo.txtEMail.value.length == 0){
document.frmInfo.txtEMail.focus();
document.frmInfo.txtEMail.select();
alert("You must enter an EMail address to continue.");
return false;
}
//--- Make sure the Comments are entered
if(document.frmInfo.txtComments.value.length == 0){
document.frmInfo.txtComments.focus();
document.frmInfo.txtComments.select();
alert("You must enter your comments to continue.");
return false;
}
return true;
}


************************

Here is the pertinent form code:

************************

<form name="frmInfo" method="POST" onsubmit="return RequiredFields()">
<INPUT TYPE="hidden" NAME="txtAction" VALUE="">



<INPUT TYPE="submit" VALUE="Submit" name="btnSubmit" onclick="RequiredFields();">


***************************

Charles
02-06-2003, 09:54 AM
Your form is calling the function RequiredFields() twice, once when the SUBMIT button is clicked and once just before the form is submitted. Get rid of the onclick handler associated with the button.

rdharris
02-06-2003, 11:49 AM
I've remover the OnClick you reccomended.

The alert still pops up nicely, and now it takes one
click like it should to clear it.

however..

With the form filld out correctly,
I need it to take all the variables
to the next page, the ASP page
which preforma a CDONT and displays
"thank you for.."

As of now, it clears the form.

I need it to got to "mail.asp"

here is the URL If you want to take a peek
at what I mean.

the form (http://www1.gnb.ca/0007/Culture/Heritage/VMC/mailer/sendmail-e.asp)

thanks again!

Rob

Charles
02-06-2003, 01:43 PM
You've simply forgotten to tell the form where to go.

<form name="frmInfo" method="POST" onsubmit="return RequiredFields()" action="mail.asp">