PDA

View Full Version : formretain.js



turbo20
01-27-2006, 10:56 PM
could someone help me with this script the link is below
http://www.dynamicdrive.com/dynamicindex16/formremember.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

jscheuer1
01-28-2006, 06:55 AM
Sure. You can link the script to both pages as described on the demo page but, remove this section from the external script:


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:


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

turbo20
01-28-2006, 06:51 PM
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:)

jscheuer1
01-28-2006, 08:56 PM
Sorry, I got that one wrong. Start over with a fresh formretain.js and add this at the top (addition red):


var memoryduration="100 days", flag=1

Then in about the middle of the function setformobjects() (addition red again):


if (retrievedvalues!=""&&flag){

Then change (at the end of the saveformvalues() function):


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

to:


document.cookie = "mvalue="+formvalues+"; path=/;expires=" + expireDate.toGMTString()

and change (about at the middle of the setformobjects() function):


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

to:


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:


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

turbo20
01-28-2006, 10:37 PM
just wanted to take the time to Thank You. Your second post
worked like a charm.:)