Click here to Skip to main content
15,896,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to run multiple functions in javascript using on submit form?
XML
<html>
<head>
<script type="text/javascript">
function first_name()
{
    if(document.f_name.firstname.value=="")

{
alert("Please enter your first name!");
return false;
}

else if(!isNaN(document.f_name.firstname.value))
    {
        alert ("Please enter only alphabets!");
        return false;
        }

else
return true;
}

function f_password()
{
if(document.f_name.pwd.value != '' && document.f_name.pwd.value == document.f_name.cpwd.value)
{
    if(document.f_name.pwd.value.length < 6)
    {
    alert("Password should be more than 6 characters!")
    }
}
else
alert("Please check your password!");
}


function f_username()
{
if(document.f_name.username.value.length < 5)
{
alert("Username should be more than 5 characters!")
}
else
return false;
}

function f_email()
{
var e=/^([a-zA-Z0-9_.-])+@+([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
if(e.test(document.f_name.email.value))
{
return true;"
}
else
{
alert("Please enter valid email!");
}

}

function phone()
{
p=/[0-9]/;
if(document.f_name.phn.value!='')
{
if(p.test(document.f_name.phn.value))
{
return true;
}
else
{
alert("Please enter only numbers!");
}

}
else
alert("Please enter phone number!");
}







function last_name()
{
if(document.f_name.lastname.value=='')
{
alert("Please enter your last name!");
}

else if(!isNaN(document.f_name.lastname.value))
    {
        alert ("Please enter only alphabets!");
        }

else
return false;
}


</script>
<link href="form.css" rel="stylesheet" type="text/css">
</head>
<body>
<center>
<table border="0" align="left" class="a">
<tr><th colspan="2" align="center"><h1>REGISTRATION FORM</h1></th></tr>
<tr><td>
&nbsp;&nbsp;
</td></tr>
<form name="f_name" method="post" onSubmit="return first_name(); return last_name(); return f_username(); return f_email(); return f_password(); return phone()">
<tr><th class="bt">
Firstname:</th><th><input type="text" name="firstname" size="33">
</th></tr>

<tr><th class="bt">
Last Name:</th><th>

    <input type="text" name="lastname" size="33">

</th></tr>


</td></tr>


<tr><th class="bt">
Username:</th><th><input type="text" name="username" size="33">
</th></tr>

<tr><th class="bt">
Email:</th><th><input type="text" name="email" size="33">
</td></tr>

<tr><th class="bt">
Password:</th><th><input type="password" name="pwd" size="33">
</th></tr>

<tr><th><span class="bt">
Confirm password:</span></th>
  <th> <span class="bt">
    <input type="password" name="cpwd" size="33">
  </span></th>
</tr>

<tr><th class="bt">

Phone no.:</th><th><input type="text" name="phn" size="33" >
</th></tr>

<tr><th class="bt">
Gender:</th><th><input type="radio" value="male" name="gender">
  <span class="bt">Male</span>
  <input type="radio" name="gender" value="female">
  <span class="bt">Female</span></th></tr>

<tr><th align="center" colspan="2">
<center>
<input type="submit" value="Submit" name="submit">
</center>
</th></tr>

</form>
</table>
</center>


<center>

</center>
</body>
</html>


when i run this code no validation performed plz help me...............
Posted

1 solution

the problem is with your logic.

agregate all the called function in one function. an then return the summery. example below:
JavaScript
function varify()
{
if(element.value)=="")
return false

if(element2.value=="")
return false 

return true 
}
 
Share this answer
 
Comments
shairykalra2 10-Oct-12 3:41am    
Sry i dont get how to call all function in one fubnction plz help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900