Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
how to run multiple functions in javascript using on submit form?
<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 8-Oct-12 22:25pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

the problem is with your logic.
 
agregate all the called function in one function. an then return the summery. example below:
function varify()
{
if(element.value)=="")
return false
 
if(element2.value=="")
return false 
 
return true 
}
  Permalink  
Comments
shairykalra2 at 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)

  Print Answers RSS
0 CPallini 365
1 Sergey Alexandrovich Kryukov 277
2 OriginalGriff 165
3 George Jonsson 159
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,860
2 CPallini 5,125
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100