Current location: Hot Scripts Forums » General Web Coding » JavaScript » Remember Me


Remember Me

Reply
  #1 (permalink)  
Old 03-28-10, 05:41 PM
hunterhdolan hunterhdolan is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 30
Thanks: 5
Thanked 0 Times in 0 Posts
Remember Me

Ok so I am working on a remember me script. Here is what I have so far

index.html

HTML Code:
<head><title>Remember Me</title><script type="text/javascript" src="rememberMe.js"></script></head>
<body>

<form name="form" action="hello.html" method="post" onsubmit="if (this.checker.checked) toMem(this)">
 <table border="0" cellpadding="0" cellspacing="3" align="center" width="460">
  <tr>
    <td width="170" align="right">
      Name:   
    </td>
    <td width="290">
     <input size="30" name="name" id="name">
    </td>

  </tr>
  <tr>
    <td width="170" align="right">
      E-mail:   
    </td>
    <td width="290">
     <input size="30" name="email" id="email">
    </td>
  </tr>
  <tr>
    <td width="170" align="right">
      Remember me?:   
    </td>
    <td width="290">
     <input type="checkbox" id="checker" name="checker">
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center">
      <input type="submit" value="Submit"> 
      <input type="reset" value="Reset"> 
      <input type="button" onclick="delMem(this)" value="Delete Information">
    </td>
  </tr>
 </table>
</form>
</body>
And rememberme.js

HTML Code:
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Cookie script - Scott Andrew
Popup script, Copyright 2005, Sandeep Gangadharan */

function newCookie(name,value,days) {
 var days = 10;   // the number at the left reflects the number of days for the cookie to last
                 // modify it according to your needs
 if (days) {
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = "; expires="+date.toGMTString(); }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/"; }

function readCookie(name) {
   var nameSG = name + "=";
   var nuller = '';
  if (document.cookie.indexOf(nameSG) == -1)
    return nuller;

   var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length); }
    return null; }

function eraseCookie(name) {
  newCookie(name,"",1); }

function toMem(a) {
    newCookie('theName', document.form.name.value);     // add a new cookie as shown at left for every
    newCookie('theEmail', document.form.email.value);   // field you wish to have the script remember
}

function delMem(a) {
  eraseCookie('theName');   // make sure to add the eraseCookie function for every field
  eraseCookie('theEmail');

   document.form.name.value = '';   // add a line for every field
   document.form.email.value = ''; }


function remCookie() {
document.form.name.value = readCookie("theName");
document.form.email.value = readCookie("theEmail");
}

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  remCookie();
});
and hello.html

HTML Code:
Success!
If you check remember me the form will be filled in automatically the next time you go on because of the cookie it save on your computer. Is there any way that it could along with filling in the form automatically press the submit button? I am not very good a JS (brand new to it) please help me!

BTW I know that it is not actually a login form. It is just a demo.
Thanks!
-HD
__________________
I was laying in bed last night looking at the stars..... Then it occurred to me. Where the hell is the ceiling!
Reply With Quote
  #2 (permalink)  
Old 03-29-10, 02:13 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
HTML Code:
<form id="the_form" ...

<input type="submit" value="Submit" id="submit_button" /> 
<script type="text/javascript">
/* After cookie is read and processed */
document.getElementById('submit_button').click();

/* --or-- */
document.getElementById('the_form').submit();
</script>
Not tested
Reply With Quote
  #3 (permalink)  
Old 03-29-10, 09:52 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Fairly simple to do.
Note the changes to the remCookie() function.

rememberme.js
HTML Code:
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Cookie script - Scott Andrew
Popup script, Copyright 2005, Sandeep Gangadharan */

function newCookie(name,value,days) {
 var days = 10;   // the number at the left reflects the number of days for the cookie to last
                 // modify it according to your needs
 if (days) {
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));
   var expires = "; expires="+date.toGMTString(); }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/"; }

function readCookie(name) {
   var nameSG = name + "=";
   var nuller = '';
  if (document.cookie.indexOf(nameSG) == -1)
    return nuller;

   var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length); }
    return null; }

function eraseCookie(name) {
  newCookie(name,"",1); }

function toMem(a) {
    newCookie('theName', document.form.name.value);     // add a new cookie as shown at left for every
    newCookie('theEmail', document.form.email.value);   // field you wish to have the script remember
}

function delMem(a) {
  eraseCookie('theName');   // make sure to add the eraseCookie function for every field
  eraseCookie('theEmail');

   document.form.name.value = '';   // add a line for every field
   document.form.email.value = ''; }


function remCookie() {
var nameObj = document.form.name;
var emailObj = document.form.email;
nameObj.value = readCookie("theName");
emailObj.value = readCookie("theEmail");
if(nameObj.value && emailObj.value){document.form.submit();}
}

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  remCookie();
});
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i set cookies to remember username shemi PHP 4 08-05-09 08:08 AM
Remember user name with PHP/Cookies shinfonimous Script Requests 3 05-20-08 04:10 PM
When times are hard.....remember this. DPR001 General Advertisements 1 06-12-05 06:11 AM
Remember "selected" option on dropdown menu dihan PHP 4 04-28-05 12:07 PM


All times are GMT -5. The time now is 02:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.