...

View Full Version : form validation problem



angst
10-22-2005, 08:06 PM
Hello,
I'm trying to use the fallowing script for form valildation, it does give me the alert message when feilds are not completed, but when I click ok, it submits the page anyway,,
any ideas???

thanks in advance for your time!



<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{

if (form.fname.value == "" &&
form.lname.value == "" &&
form.phone.value == "" &&
form.serv.value == "" &&
form.month.value == "-" &&
form.day.value == "-" &&
form.time.value == "-")
{
alert( "Please complete all feilds!" );
form.email.focus();
return false ;
}

//return true ;
}
//-->
</script>
<form action='sendmail.php' method='post' onsubmit="return checkform(this);">

Lerura
10-22-2005, 08:46 PM
you have set it to only return false when no fields are filled by using the &&;
an beside that you have made a few typo's
the correct script is:
function checkform (form)
{

if (form.fname.value == "" ||
form.lname.value == "" ||
form.phone.value == "" ||
form.serv.value == "" ||
form.month.value == "-" ||
form.day.value == "-" ||
form.time.value == "-")
{
alert("Please complete all fields!");
form.email.focus();
return false;
}else{
return true;}
}
}

if month day and time is chosen from a dropdownmenu then you must use:
e.g. form.day[form.day.selectedIndex].value



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum