logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Event for textbox validation doesnt fire
Author
peacemaker



Joined: 23 May 2008
Posts: 80

PostPosted: Sun 08 Jun '08 4:54    Post subject: Event for textbox validation doesnt fire Reply with quote

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()"/>&nbsp;&nbsp;&nbsp;
Password <input type="password" name="Password" onChange="TxtMsg()"/>&nbsp;&nbsp;&nbsp;
<input type="Submit" name="SignIn" value="Sign In" onclick="TxtMsg()"/>&nbsp;&nbsp;&nbsp;
<a href="jacob.php">Forgot Password/ID </a>&nbsp;&nbsp;
<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

PostPosted: Mon 28 Jul '08 17:00    Post subject: Reply with quote

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" />&nbsp;&nbsp;&nbsp;
Password <input type="password" name="Password" />&nbsp;&nbsp;&nbsp;
<input type="Submit" name="SignIn" value="Sign In" />&nbsp;&nbsp;&nbsp;
<a href="jacob.php">Forgot Password/ID </a>&nbsp;&nbsp;
<a href="logout.php">Logout </a>
</form>
</body>
</html>
Back to top


Reply to topic   Topic: Event for textbox validation doesnt fire View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner