Computer Hope

Internet & Networking => Web design => Topic started by: Bannana97 on January 19, 2009, 02:41:31 PM

Title: Whats wrong with this Script?
Post by: Bannana97 on January 19, 2009, 02:41:31 PM
It keeps saying invalid login even when i enter the correct info.






<html>
<head>
<title>Login</title>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="Bannana97" && password=="se5asokn1") { window.location="userbailey451497529.html"; done=1; }
if (username=="micky" && password=="bailey") { window.location="usermicky00000191.html"; done=1; }
if (username=="apple202" && password=="passlolword") { window.location="userapple202ifsdhgio.html"; done=1; }
if (done==0) { alert("Invalid login!"); }
}
// End -->
</SCRIPT>
</head>
<body>
<script link="http://www.herbertsworld.com/scriptholder.html" >
</script>
<center>
<form name=login>
<table width=225 border=1 cellpadding=3>
<tr><td colspan=2><center><font size="+2">Login: Account</font></center></td></tr>
<tr><td>Username:</td><td><input type="text" name="username" /></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" /></td></tr>
<tr><td colspan=2 align=center><input type=button value="Login!" onClick="Login()"></td></tr>
</table>
</form>
</center>
</body>
</html>
Title: Re: Whats wrong with this Script?
Post by: kpac on January 19, 2009, 02:46:10 PM
<script link="http://www.herbertsworld.com/scriptholder.html" >
</script>

You are missing a type attribute and "link" should be "src". It should be:

<script src="http://www.herbertsworld.com/scriptholder.html">
</script>


I'm not sure if that will work as it is a HTML file...
Title: Re: Whats wrong with this Script?
Post by: Bannana97 on January 19, 2009, 03:37:23 PM
No that isnt the problem, It works for all my other pages.

The login keeps saying Login Incorrect even with the correct info.
Title: Re: Whats wrong with this Script?
Post by: EchoLdrWolf316 on January 19, 2009, 07:51:21 PM
I'd say the problem is that your running the  'if (done==0) { alert("Invalid login!"); }'  script on the same level as 'var done=0;' so it's immediately activating. I'm not good with javascript, but a tabbed
Code: [Select]
else if () command might work.
Title: Re: Whats wrong with this Script?
Post by: kpac on January 20, 2009, 02:15:32 AM
I'd say the problem is that your running the  'if (done==0) { alert("Invalid login!"); }'  script on the same level as 'var done=0;' so it's immediately activating. I'm not good with javascript, but a tabbed
Code: [Select]
else if () command might work.

Yes, this could be the problem.

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="Bannana97" && password=="se5asokn1") { window.location="userbailey451497529.html"; done=1; }
elseif (username=="micky" && password=="bailey") { window.location="usermicky00000191.html"; done=1; }
elseif (username=="apple202" && password=="passlolword") { window.location="userapple202ifsdhgio.html"; done=1; }
else  { done==0; alert("Invalid login!"); }
}
// End -->
</SCRIPT>


You might also have a problem with the username and password variables. To me, you are defining the same variables twice.

var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();


Might be something like this:

var user=document.login.username.value;
username=user.toLowerCase();
var pass=document.login.password.value;
password=pass.toLowerCase();
Title: Re: Whats wrong with this Script?
Post by: BC_Programmer on January 20, 2009, 03:04:28 AM
No that isnt the problem, It works for all my other pages.

The login keeps saying Login Incorrect even with the correct info.

yeah, it's not a problem that your using attributes that don't exist.  ::)