validation errors

admin

Administrator
Staff member
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=http://www.webdeveloper.com/forum/archive/index.php/"">



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


***************************
 
Back
Top