Results 1 to 5 of 5

Thread: formretain.js

  1. #1
    Join Date
    Jan 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default formretain.js

    could someone help me with this script the link is below
    http://www.dynamicdrive.com/dynamici...rmremember.htm
    What I would like to do is take the input from a one line form and
    input it to the cookie. that is easy but I do not want the information
    to re-appear in the original form after submission but rather the second page that comes up would have it.

    so the first page should only be able to input to the cookie not recall it.
    can it be done?
    Thanks, Don

  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

    Sure. You can link the script to both pages as described on the demo page but, remove this section from the external script:

    Code:
    if (window.addEventListener)
    window.addEventListener("load", setformobjects, false)
    else if (window.attachEvent)
    window.attachEvent("onload", setformobjects)
    else if (document.getElementById)
    window.onload=setformobjects
    Then, on the second page, put a script block containing the above removed code below the link to the script:

    Code:
    <script type="text/javascript" src="formretain.js">
    
    /***********************************************
    * Remember Form Values script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    </script>
    
    <script type="text/javascript">
    if (window.addEventListener)
    window.addEventListener("load", setformobjects, false)
    else if (window.attachEvent)
    window.attachEvent("onload", setformobjects)
    else if (document.getElementById)
    window.onload=setformobjects
    </script>
    Just make sure that the text input on both pages is in an identical position in the document tree relative to all other text inputs with the memorize class set. This sounds more complicated than it is. It means if the text input on the first page is the first text input on that page with the class="memorize", the text input on the second page must also be the first text input on that page with the class="memorize". Oh, and both inputs must be in forms, they cannot be free standing text inputs. Hidden text inputs could be used to fudge the order, if necessary but, if it is only the one field, there should be no need.
    - John
    ________________________

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

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

    Default thanks, can you explain

    Firstly, thank you very much for your response, but could you put
    it in a "for Dummies" version? I did as instructed and could not get it to work.
    any further help would be appreciated.
    Don

  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

    Sorry, I got that one wrong. Start over with a fresh formretain.js and add this at the top (addition red):

    Code:
    var memoryduration="100 days", flag=1
    Then in about the middle of the function setformobjects() (addition red again):

    Code:
    if (retrievedvalues!=""&&flag){
    Then change (at the end of the saveformvalues() function):

    Code:
    document.cookie = "mvalue"+window.location.pathname+"="+formvalues+"; path=/;expires=" + expireDate.toGMTString()
    to:

    Code:
    document.cookie = "mvalue="+formvalues+"; path=/;expires=" + expireDate.toGMTString()
    and change (about at the middle of the setformobjects() function):

    Code:
    var retrievedvalues=get_cookie("mvalue"+window.location.pathname)
    to:

    Code:
    var retrievedvalues=get_cookie("mvalue")
    Now, on our first page, use the script call in the head of the page as described in the demo and follow it with this script block, like so:

    Code:
    <script type="text/javascript" src="formretain.js">
    
    /***********************************************
    * Remember Form Values script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    </script>
    <script type="text/javascript">
    flag=0
    </script>
    On your second page, just use the script call in the head as in the demo.
    - John
    ________________________

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

  5. #5
    Join Date
    Jan 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking thank you

    just wanted to take the time to Thank You. Your second post
    worked like a charm.

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
  •