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);
}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.