Results 1 to 8 of 8

Thread: Recall Form Values Script II

  1. #1
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Recall Form Values Script II

    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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

  3. #3
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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

  5. #5
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So what is the difference between this script and the one here which enables it to work???

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by trippin View Post
    So what is the difference between this script and the one here which enables it to work???
    The main difference is that I wrote the script in this thread from scratch with the specific purpose in mind of saving the password. The other script you are referencing was written by someone else, I believe specifically to save text field values.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:
    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>
    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.

  8. #8
    Join Date
    Jan 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •