Jump to content

please can someone point me in the right direction


robbaust

Recommended Posts

Hi please could someone help me

 

I'm trying to learn javascript from a book and some online tuts but have lost myself in it all

 

basically I want to create a user registration page which then saves the users username and password to a cookie then redirects the user to a login page, once on the login page the user enters there username and password then gains access to say a members page.

 

I just can't seem to tie them together and I know this is not secure but this will never go online as like I said I'm just learning javascript

 

These are the codes I have been working with, sorry if these look totally rubbish

 

Thank You very much in advance for any help offered

 

Robert

 

PS: I really want to learn this so please don't tell me to go look at jquery or PHP thank you

 

user_register.html

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script  src="cookieFunction.js"></script>
</head>

<body>
<body id="body" onLoad="checkCookie()">
<form name="user_register">

Username: <input type="text" name="user" size="20" value="user"><p>
Password: <input type="text" name="pass" size="20"><p>
<input type="button" value="login" onClick="setCookie()">
  
</form>
</body>
</html>

 

loginForm.html

 

<html>
<head>

<title>Untitled Document</title>
<script src="file:///UNI STUFF/javawebsite/cookieFunction.js"></script>
<script type="javascript">

function setCookie()
{
setCookie("user".document.loginForm.user,value,365);
setCookie("pass".document.loginForm.pass,value,365);
}
</script>
</head>

<body>
<body onload="checkCookie()">
<script type="javascript">
user = getCookie("user");
pass = getCookei("pass");

</script>

<form name="loginForm">

Username: <input type="text" name="user" size="20" value="user"><p>
Password: <input type="text" name="pass" size="20"><p>
<input type="button" value="login" onClick="http://www.google.co.uk">
  
</form>
</p>
</body>
</html>

 

cookieFunction.js

 

function setCookie(loginForm,value,exdates)
{
var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdate);
    var cookieValue = escape (value) + ((exdate == null) ? "": ";expires= " + exdate.toUTCSring());
    document.cookie=cookieName + " = " + cookieValue ; 
}

function getCookie(loginForm)
{
var i,x,y,cookieTray=document.cookie.split(";");
    for (i=0;i<cookieTray.length;i++)
    {
    	x=cookieTray[i].substr(0,cookieTray[i].indexOF("="));
        y=cookieTray[i].substr(cookieTray[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==loginForm) { return unescape(y);}
}
        return(null);
}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.