1) Script Title:
Recall Form Values Script II
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamici...mremember2.htm
3) Describe problem:
http://www.dynamicdrive.com/forums/s...ad.php?t=17241
1) Script Title:
Recall Form Values Script II
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamici...mremember2.htm
3) Describe problem:
http://www.dynamicdrive.com/forums/s...ad.php?t=17241
Try this out:
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> function createCookie(name,value,days) { 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 nameEQ = name + "="; 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(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } function retrieve_password(){ if(readCookie('pwrd')){ var thepass=document.getElementsByTagName('input'); for (var i_tem = 0; i_tem < thepass.length; i_tem++) if(thepass[i_tem].type=='password') thepass[i_tem].value=readCookie('pwrd'); } } function save_password(){ if(document.getElementById('spw').checked){ var thepass=document.getElementsByTagName('input'); for (var i_tem = 0; i_tem < thepass.length; i_tem++) if(thepass[i_tem].type=='password') createCookie('pwrd',thepass[i_tem].value) } else eraseCookie('pwrd') } if ( typeof window.addEventListener != "undefined" ) window.addEventListener( "load", retrieve_password, false ); else if ( typeof window.attachEvent != "undefined" ) window.attachEvent( "onload", retrieve_password ); else { if ( window.onload != null ) { var oldOnload = window.onload; window.onload = function ( e ) { oldOnload( e ); retrieve_password(); }; } else window.onload = retrieve_password; } if ( typeof window.addEventListener != "undefined" ) window.addEventListener( "unload", save_password, false ); else if ( typeof window.attachEvent != "undefined" ) window.attachEvent( "onunload", save_password ); else { if ( window.onunload != null ) { var oldOnunload = window.onunload; window.onunload = function ( e ) { oldOnunload( e ); save_password(); }; } else window.onunload = save_password; } </script> </head> <body> <form action=""> <input type="password" name=""><br> save password?<input type="checkbox" id="spw"> </form> </body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Thanks that worked beautifully!
Now how would I go about adding another text input above the password input and have them both write to the same cookie?
My thinking was that rather than rewrite other saving scripts into this one, this script could be used along with pretty much any other script that does that sort of thing (saves text fields or whatever).
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
So what is the difference between this script and the one here which enables it to work???
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
The reason I asked this is because I have been messin around with your code and can't get a text input to write to this same cookie. I've tried using it along with the Form Recall Script II. When I do this only the password is saved by your script.
I am using a form like so:
Also I noticed that the status of the checkbox was not being recorded to cookie so when I leave the site and come back the cookie is erased because the checkbox becomes empty.HTML Code:<form name="manlog" action="/">ID: <input type="text" name="login"><BR>PW: <input type="password" name="passwd"><br> Save Login?<input type="checkbox" id="persistbox"><br> <input type="submit" value="Login"> </form>
I did it! This script will save ALL fields or SPECIFIC fields in the form you specify and write them to a cookie. I had a lot of problems with trying to write the password value to cookie but not anymore.
HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script src="logincookie.js" type="text/javascript"></script> </head> <body onload="recoverInputs(document.forms.manlog,retrieveCookie('y_login'),true);"> <form name="manlog" action="/">ID: <input type="text" name="login"><BR>PW: <input type="password" name="passwd"><br> Save Login?<input type="checkbox" id="remember"><br> <input type="reset" name="g"> <input type="button" value="Save" onclick="rememberme()"> <input type="button" value="Recover" onclick="recoverInputs(this.form,retrieveCookie('y_login'),true);"> </form> </body> </html>
Bookmarks