/    Sign up×
Community /Pin to ProfileBookmark

JavaScript Error

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>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@GreelmoauthorMay 13.2003 — sorry, ignore the second variable (passy) in the function.
Copy linkTweet thisAlerts:
@AdamBrillMay 13.2003 — Is this what your looking for?&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login&lt;/title&gt;
&lt;SCRIPT LANGUAGE = "JavaScript"&gt;
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 &lt; arrUn.length; i++){
if(arrUn[i].toLowerCase()==namey.toLowerCase()){
if(asky.toLowerCase()==arrPw[i].toLowerCase()){
alert("Correct")
break;
}else{
alert("Name not recognized")
break;
}
}
}
}
&lt;/script&gt;
&lt;body&gt;
&lt;form name="form1"&gt;
&lt;b&gt;Username:&lt;/b&gt;
&lt;input type="text" name="text1"&gt;
&lt;br&gt;
&lt;input type="button" value="Login" style="background:aqua;"
onClick="fnclog(this.form.text1.value);"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
If not, please let me know how you want it changed...
Copy linkTweet thisAlerts:
@GreelmoauthorMay 13.2003 — 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.
Copy linkTweet thisAlerts:
@CharlesMay 13.2003 — [font=georgia]You can make that a bit simpler by using an object.[/font]

[font=monospace]<!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>[/font]
×

Success!

Help @Greelmo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...