By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,818 Members | 2,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,818 IT Pros & Developers. It's quick & easy.

Anybody can help me on this javascript program Please.

P: n/a
nyy
This is a program that is supposed to save the user name and password
in cookies, and when the user comes back to login and he enters the
same user name and password, a pop up message welcome him or her. If
after three tries the user don't enter the same User/pass, let the user
knows it is his or her time on the page. Thanks and here is so far what
I have. help is appreciate it. Thanks again.

<HTML>
<HEAD>
<TITLE>Badia</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function LogIn(){
loggedin=false;
username="";
password="";
username=prompt("Username:","");
password=prompt("Password:","");

if (username=="" || password=="")
{
alert("Invalid login, please try again!");
}
if (username!="" && password!="");
{
alert("Your user name and password has been saved!");
}
}
</SCRIPT>
</HEAD>

<BODY>
<center>
<h1>WEB 420 </h1>
<h2>Badia</h2>
</center>

<center>
<form><input type=button value="Login!" onClick="LogIn()">
</form>
</center>

</BODY>
</HTML>

Sep 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
nyy wrote:
This is a program that is supposed to save the user name and password
in cookies, and when the user comes back to login and he enters the
same user name and password, a pop up message welcome him or her. If
after three tries the user don't enter the same User/pass, let the user
knows it is his or her time on the page. Thanks and here is so far what
I have. help is appreciate it. Thanks again.


Where are the <input>s for the username and password?

What is the "prompt()" function that you attempt to call?

Where are you doing *anything* with cookies?

Why would you save username and password in something as unsecure as
cookies?

Sep 17 '05 #2

P: n/a
> If after three tries the user don't enter the same User/pass, let the user
knows it is his or her time on the page.
What does that mean?
username=prompt("Username:","");
password=prompt("Password:","");

if (username=="" || password=="")
{
alert("Invalid login, please try again!");
}
Your next step would be to put the above in a loop
to repeat it if necessary. To have been given such
an assignment, you must have been taught about
loops. I would not bother with an alert here:

while( ( username=prompt("Username:","") )== "" )
;

If the user closes the dialog, prompt() returns
'undefined', but don't worry about that for now.

if (username!="" && password!="");
{
alert("Your user name and password has been saved!");
}
}


Again I would assume that you must have been
introduced to using cookies. I think for this
exercise, session cookies would be adequate
and their availability can be assumed.

document.cookie="cookieName=" + cookieValue;

document.cookie is a string comprised of all the
cookies for the current domain, each delimited by
a semicolon. The trick is to find the position of
yours, perhaps using String.indexOf(), then using
that as a starting point to extract the value on
the other side of the '=' sign.

--
S.C.

Sep 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.