hi evryone.....i would like to ask your favour regarding on my php code.....this is my code....
I would like to use function valForm when clicking on submit button....unfor tunately, the validation function and the validate form is not working.....som ebody plz help me.....
Code:
<html>
<head>
<title>
</title>
<script type="text/javascript">
function validation()
{
var valid=true;
if(document.form2.icnumber.value=="")
{
alert(" Please fill in the ' Identification Card Number ' textbox. ");
document.form2.icnumber.focus();
valid=false;
}
if(document.form2.name.value=="")
{
alert(" Please fill in the ' Name ' textbox. ");
document.form2.name.focus();
valid=false;
}
if(document.form2.position.value=="")
{
alert(" Please fill in the ' Position ' textbox. ");
document.form2.position.focus();
valid=false;
}
if(document.form2.department.value=="")
{
alert(" Please fill in the ' Department ' textbox. ");
document.form2.department.focus();
valid=false;
}
/*if(document.form2.email.value=="")
{
alert(" Please fill in the ' Email ' textbox. ");
document.form2.email.focus();
valid=false;
}*/
if(document.form2.phoneno.value=="")
{
alert(" Please fill in the ' Phone Number ' box. ");
document.form2.phoneno.focus();
valid=false;
}
if(document.form2.username.value=="")
{
alert(" Please fill in the ' User Name ' textbox. ");
document.form2.username.focus();
valid=false;
}
if(document.form2.password.value=="")
{
alert(" Please fill in the ' Password ' box. ");
document.form2.password.focus();
valid=false;
}
return valid;
}
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}
return true
}
function ValidateForm()
{
var emailID=document.form2.email
if ((emailID.value==null)||(emailID.value==""))
{
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
function valForm()
{
validateForm();
validation();
}
</script></head>
<body>
<form name="form2" method="post" action="register0.php" onSubmit="return valForm();">
<table border=3>
<tbody>
<tr>
<td style="text-align: center;">
<p><strong>Registration Form</strong></p>
<table border="0" cellspacing="1" cellpadding="3">
<tbody>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">Identification Card Number</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="text" name="icnumber"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">Name</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="text" name="name"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">Position</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="text" name="position"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">Department</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="text" name="department"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">Email</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="text" name="email"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">Phone Number</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="text" name="phoneno"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">User Name</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="text" name="username"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td><span style="font-family: Arial; font-size: small;">Password</span></td>
<td><span style="font-family: Arial; font-size: small;"> : </span></td>
<td><span style="font-family: Arial; font-size: small;"><input type="password" name="password"></span></td>
</tr>
<tr align="left" bgcolor="#FFFFFF">
<td colspan=3 align=center><span style="font-family: Arial; font-size: small;"><input type="submit" name="submit" value="Send Form"><input type="reset" name="reset" value="Empty Form"></span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
I would like to use function valForm when clicking on submit button....unfor tunately, the validation function and the validate form is not working.....som ebody plz help me.....
Comment