Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Event for textbox validation doesnt fire |
|
Author |
|
peacemaker
Joined: 23 May 2008 Posts: 80
|
Posted: Sun 08 Jun '08 4:54 Post subject: Event for textbox validation doesnt fire |
|
|
Hello friends,
I am trying to accept username and password from user. And trying to validate whether they are empty or nt. If they are empty the function in javascript will give message but its not work help appricated.
I will appricate if any one find out error in my code and tell whether the events i used are correct or nt.
<html>
<head>
<script language="javascript" type="text/javascript">
function TxtMsg()
{
If(document.LoginFrm.UserName.value=="") OR
If(document.LoginFrm.Password.value=="")
{
alert("Please enter User Name and Password ");
}
}
function ValidateForm(form)
{
if(IsEmpty(form.UserName))
{
alert('You have not entered an account number')
form.UserName.focus();
return false;
}
if (IsEmpty(form.Password))
{
alert('Please enter only numbers or decimal points in the account field')
form.Password.focus();
return false;
}
return true;
} </script>
<body>
<form name="LoginFrm" method="post" action="work.html" onSubmit="TxtMsg()">
User Name <input type="text" name="UserName" onChange="TxtMsg()"/>
Password <input type="password" name="Password" onChange="TxtMsg()"/>
<input type="Submit" name="SignIn" value="Sign In" onclick="TxtMsg()"/>
<a href="jacob.php">Forgot Password/ID </a>
<a href="logout.php">Logout </a>
</form>
</body>
</html>
I was trying both the functions so there are both the function and i was trying by everymeans so that they fire. so thats why after every text box there is function.
which one is correct plz rectify.
Thanks for the help in advance. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 28 Jul '08 17:00 Post subject: |
|
|
This works
Code: |
<html>
<head>
<script language="javascript" type="text/javascript">
function TxtMsg(){
if( (document.forms['LoginFrm'].UserName.value=="") || (document.forms['LoginFrm'].Password.value=="") )
{
alert("Please enter User Name and Password ");
return false;
}
}
</script>
<body>
<form name="LoginFrm" method="post" action="work.html" onSubmit="return TxtMsg();">
User Name <input type="text" name="UserName" />
Password <input type="password" name="Password" />
<input type="Submit" name="SignIn" value="Sign In" />
<a href="jacob.php">Forgot Password/ID </a>
<a href="logout.php">Logout </a>
</form>
</body>
</html>
|
|
|
Back to top |
|
|
|
|
|
|