Anybody can help me on this javascript program Please.

N

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>
 
E

ExGuardianReader

nyy said:
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?
 
S

Stephen Chalmers

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top