Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic login form validation problem 1

Status
Not open for further replies.

newbie425

Programmer
Jan 27, 2003
16
US
Hi,

I'm using a basic login script to control access to a page.

This is my script (in the head tag):
<script language="javascript">
<!--//
function dbLogin (form)
{
if (loginform.login.value=="dashboard") {
if (loginform.password.value=="PsWd123") {
window.location="dashboard.html";
}
else {
alert("Incorrect Password!");
}
}
else {
alert("Incorrect Login!");
}
}
//-->
</script>

This is my form tag:
<form name="loginform" onSubmit="dbLogin(this.form)">

This is my submit button:
<input type="submit" value="Submit">

I've tried it another way as well...

form tag: <form name="loginform">
submit btn: <input type="submit" value="Submit" onClick="dashboardLogin(this.form);">

Neither way redirects me to dashboard.html when the login and password are correct.

What am I missing??? Please help! Thanks!!

 
Hi bean1234,

Thanks for your reply. I changed the parameter name, but it still didn't work. You mean

onSubmit="dbLogin(this.form)"
CHANGE TO
onSubmit="dashboardLogin(loginform)"

right?


Does it matter that I'm working on a shared drive right now (this is my development environment) and not a web server?

Thanks.
 
Oops, I'm confusing my functions. I meant

onSubmit="dbLogin(this.form)"
CHANGE TO
onSubmit="dbLogin(loginform)"
 
Could you not change your button to this:-

Code:
<input type="button" value="Submit" onClick="dbLogin();">

and your javascript to this

Code:
function dbLogin ()
{
   if (document.loginform.login.value=="dashboard") {
         if (document.loginform.password.value=="PsWd123") {
          window.location="dashboard.html";
        }
        else {
          alert("Incorrect Password!");
        }
   }
   else {
        alert("Incorrect Login!");
    }
}

Hope this helps

Stewart.
 
Thanks that did work. The only thing is I need the button to be of type submit. Originally, I had an image instead of a button and I got a complaint that the user can't just hit enter so I'm switching to a button. Is there a way to fix that with the image?

Thanks stewart.
 
Hi delpierro,

That onclick was for the image? This is what I had:
<a href="javascript:dbLogin(this.form)"><img src="images/submit.jpg" alt="" border="0">

I changed to:
<a href="javascript:dbLogin(this.form)" onclick = "loginform.submit()"><img src="images/submit.jpg" alt="" border="0">

I was getting an error on "this.form".

Hitting Enter doesn't work.
 
On delpierro's idea, did you close your <a> tag?

Not sure the effect this will have but in your example code you haven't included </a>
 
good eyes, i didn't close the a tag at first, but i did now and it still didn't work...

should i go back to using the button? if so, is there i can make it work using <input type=submit> instead of type=button?

thanks much!
 
I tried checking keycode 13. It didn't work. I get the orginal problem where I'm not directed to the next page.
 
I'll show you what I see is wrong:
(from original post)

Code:
<script language="javascript">
<!--//
function dbLogin()
{
   if (loginform.login.value=="dashboard") {
       if (loginform.password.value!="PsWd123") {
          alert("Incorrect Password!");
          [!]return false;[/!]
       }
   }
   else {
        alert("Incorrect Login!");
        [!]return false;[/!]
    }
[!]return true;[/!]
}
//-->
</script>

This is my form tag:
<form [!]action="dashboard.html" method="post"[/!] name="loginform" onSubmit="[!]return[/!] dbLogin()">

This is my submit button:
<input type="submit" value="Submit">



[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top