Click to See Complete Forum and Search --> : JavaScript Error


Greelmo
05-13-2003, 10:27 AM
I can't get this function to work out... all i want is a login thing. I know that it will be insecure, but that is okay for my purposes. all i need is help on how to get this code to work...

Here is the code:

<html>
<head>
<title>Login</title>
<SCRIPT LANGUAGE = "JavaScript">
var arrUn = new Array("Joe", "Earl", "Bob", "Chris", "Fred");
var arrPw = new Array("haha", "hoho", "heehee", "hoohoo", "harhar");
function fnclog(namey, passy);
{
for(i = 0, i < arrUn.length, i++)
{
if(arrUn[i].toLowerCase==namey.toLowerCase)
{
asky=prompt("Password?");
if(asky.toLowerCase==arrPw[i].toLowerCase)
{alert("Correct")};
else{alert("Name not recognized")}

else{alert("Name not recognized.")}
}}
</script>
<body>
<form name="form1">
<b>Username:</b>
<input type="text" name="text1">
<br>
<input type="button" value="Login" style="background: 'aqua'"
onClick="fnclog(this.form.text1.value, this.form.pass1.value);">
</form>
</body>
</html>

Greelmo
05-13-2003, 10:28 AM
sorry, ignore the second variable (passy) in the function.

AdamBrill
05-13-2003, 12:10 PM
Is this what your looking for?<html>
<head>
<title>Login</title>
<SCRIPT LANGUAGE = "JavaScript">
var arrUn = new Array("Joe", "Earl", "Bob", "Chris", "Fred");
var arrPw = new Array("haha", "hoho", "heehee", "hoohoo", "harhar");
function fnclog(namey){
asky=prompt("Password?");
for(i = 0; i < arrUn.length; i++){
if(arrUn[i].toLowerCase()==namey.toLowerCase()){
if(asky.toLowerCase()==arrPw[i].toLowerCase()){
alert("Correct")
break;
}else{
alert("Name not recognized")
break;
}
}
}
}
</script>
<body>
<form name="form1">
<b>Username:</b>
<input type="text" name="text1">
<br>
<input type="button" value="Login" style="background:aqua;"
onClick="fnclog(this.form.text1.value);">
</form>
</body>
</html> If not, please let me know how you want it changed...

Greelmo
05-13-2003, 01:17 PM
yes, i really appreciate it. I guess the only thing else i would want would be for an alert to pop up when a name isn't correct, but that isn't too difficult.. ill work it out. Thanks again.

Charles
05-13-2003, 01:34 PM
You can make that a bit simpler by using an object.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<form action="" onsubmit="return validate(this)">
<script type="text/javascript">
<!--
function validate(f) {

var users = new Object();
users.Joe = 'haha';
users.Earl = 'hoho';
users.Bob = 'heehee';
users.Chris = 'hoohoo';
users.Fred = 'harhar';

if (!users[f.user.value]) {alert('User unknown'); return false};
if (users[f.user.value] == prompt('Password?')) {alert('Correct')} else {alert('Incorrect'); return false};
}
// -->
</script>
<div>
<input type="text" name="user">
<input type="submit" value="Log In">
</div>
</form>