| View previous topic :: View next topic |
| Author |
Message |
gilbertsavier
Joined: 26 Jun 2009 Posts: 17
|
Posted: Tue Jun 30, 2009 9:58 am Post subject: Form Validation Problem |
|
|
Hi,
I am trying to validate a form, and am getting the error messages as needed, but it submits the form anyway.
Here is the Java:
function validate (form){
var returnValue = true;
var email = CSLavRequestForm.email.value;
var phone = CSLavRequestForm.phoneNumber.value;
var groupName = CSLavRequestForm.workshopName.value;
if (email.length < 6){
returnValue = false;
alert("Please Enter Valid email");
CSLavRequestForm.email.focus();
}
if (phone.length < 10){
returnValue = false;
alert("Please Enter Valid Phone Number");
CSLavRequestForm.phone.focus();
}
if (groupName.length < 3){
returnValue = false;
alert("Please Enter Valid Workshop/Region");
CSLavRequestForm.groupName.focus();
}
return returnValue;
}
</script>
and the form line in the html:
<form onsubmit="return validate(this);" action="/cgi-sys/formmail.pl" method="post" name="CSLavRequestForm" id="CSLavRequestForm" >
I am stuck! Benn working on this for way too long _________________ Thanks & regards
Lokananth
By miOOt |
|
| Back to top |
|
 |
venkatadapa

Joined: 12 May 2008 Posts: 250
|
Posted: Wed Jul 01, 2009 4:47 am Post subject: |
|
|
Hi gilbertsavier,
You gave "returnValue=true" at starting of the function. Thats why form submited even errors occured. So In first line of the validate function replace 'returnValue=true' with 'returnValue=false'. Make this returnValue true only when after all coditions true.
I Changed your javascript code as below. It will definetely help you.
<script type="text/javascript">
function validate (frm)
{
var email = frm.email.value;
var phone = frm.phoneNumber.value;
var groupName = frm.workshopName.value;
if (email.length < 6)
{
alert("Please Enter Valid email");
frm.email.focus();
return false;
}
else if (phone.length < 10){
alert("Please Enter Valid Phone Number");
frm.phoneNumber.focus();
return false;
}
else if (groupName.length < 3){
alert("Please Enter Valid Workshop/Region");
frm.workshopName.focus();
return false;
}
return true;
}
</script>
All the best,  |
|
| Back to top |
|
 |
|