S
Shan
I am using a javascript function to validate my enquiry form.
When i tested the script, it alerts the error but after alerting
error, the form was submitted.
i didnt find any error in Error console(Firefox)
here is code that i am using ....
html part
<form name="frmName" method="POST" action="enquiry.php"
onSubmit="javascript:return validate_enquiry()">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tr class="formtext">
<td width="20%">First Name</td>
<td>
<input type="text" name="varFname" value="<?=(!
empty($val_ary['varFname'])?$val_ary['varFname']:'')?>"
class="inputbox">
</td>
</tr>
<tr class="formtext">
<td>Last Name</td>
<td>
<input type="text" name="varLname" value="<?=(!
empty($val_ary['varLname'])?$val_ary['varLname']:'')?>"
class="inputbox">
</td>
</tr>
</table>
</form>
script part
function validate_enquiry(){
var_fname = document.frmName.varFname.value;
var_fname = var_fname.replace(/^\s+|\s+$/g, '') ;
if(var_fname==''){
alert('Empty/Invalid input for First Name');
document.getElementById('varFname').focus();
return false;
}
var_lname = document.frmName.varLname.value;
var_lname =var_lname.replace(/^\s+|\s+$/g, '') ;
if (var_lname==''){
alert('Empty/Invalid input for Last Name');
document.getElementById('varLname').focus();
return false;
}
return true;
}
can any one suggest the wrong thing with my code...
i am tesing in Firefox 2....
Advance thanks for any help...
When i tested the script, it alerts the error but after alerting
error, the form was submitted.
i didnt find any error in Error console(Firefox)
here is code that i am using ....
html part
<form name="frmName" method="POST" action="enquiry.php"
onSubmit="javascript:return validate_enquiry()">
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tr class="formtext">
<td width="20%">First Name</td>
<td>
<input type="text" name="varFname" value="<?=(!
empty($val_ary['varFname'])?$val_ary['varFname']:'')?>"
class="inputbox">
</td>
</tr>
<tr class="formtext">
<td>Last Name</td>
<td>
<input type="text" name="varLname" value="<?=(!
empty($val_ary['varLname'])?$val_ary['varLname']:'')?>"
class="inputbox">
</td>
</tr>
</table>
</form>
script part
function validate_enquiry(){
var_fname = document.frmName.varFname.value;
var_fname = var_fname.replace(/^\s+|\s+$/g, '') ;
if(var_fname==''){
alert('Empty/Invalid input for First Name');
document.getElementById('varFname').focus();
return false;
}
var_lname = document.frmName.varLname.value;
var_lname =var_lname.replace(/^\s+|\s+$/g, '') ;
if (var_lname==''){
alert('Empty/Invalid input for Last Name');
document.getElementById('varLname').focus();
return false;
}
return true;
}
can any one suggest the wrong thing with my code...
i am tesing in Firefox 2....
Advance thanks for any help...