Loren Dorez

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromLoren Dorez
ToMe
SubjectSaving Multiple Forms to a Cookie
Date11 February 2007 06:28
Hi My name is Loren,

I am trying to take mutiple forms and throw them into
something like an array and then put the array into a
cookie. My current version works it take the current
form and goes through grabs the values of each element
and added it to a temport Storage Variable and
spliting it with a (`). It then put the temp variable
into a position in the array and puts the array in the
cookie. This setup allows me to save multiple forms in
a cooke and i can cycle through them. However i have 1
major flaw. When i go back to the previously save
forms i notice it only saved the values and checkboxes
are no longer check which then will not allow my
hidden drop down menus to be displayed as well. I was
wondering if there was a way to take you "Save Forms
to a cookie" code and allow for mutiple forms to be
save d to a cookie with a counter as well.. I would be
more than willing to send you the current code and
files that i have for u to look at and test to get an
better understanding of what i am stating if it is
unclear. Any help or advice would be greatly
appriecated. Also i currently am not using the You
Save form code as it only save 1 form to a cookie..


Thank You,
Loren Dorez
FromMe
ToLoren Dorez
SubjectRe: Saving Multiple Forms to a Cookie
Date12 February 2007 22:31
Loren,

> I was
> wondering if there was a way to take you "Save Forms
> to a cookie" code and allow for mutiple forms to be
> save d to a cookie

http://www.howtocreate.co.uk/jslibs/script-saveformvalues
It is not in there by design, but should be fairly easy to get around it.
All you need to do is get the string version of each form, and concatenate
them with whatever character you choose.

var formstrings = [];
for( var i = 0; i < document.forms.length; i++ ) {
  formstrings[i] = escape(getFormString(document.forms[i],true));
}
setCookie( 'formInputs', formstrings.join('|'), 604800 );

...

var recovstring = retrieveCookie( 'formInputs' );
recovstring = recovstring.split('|');
for( var i = 0; i < recovstring.length; i++ ) {
  recoverInputs(document.forms[i],unescape(recovstring[i]),true);
}


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromLoren Dorez
ToMe
SubjectRe: Saving Multiple Forms to a Cookie
Date13 February 2007 01:53
Tarquin,

That is similar to how i have my current one but heres
the problem. loop through and grab the value Example
 var formstrings = [];
 for( var i = 0; i < document.forms.length; i++ ) {
    formstrings[i] =
getFormElement(document.forms.elements[i].value);
 }

Is this why the check boxes arent saved when i reload
the form?. If i change from value to String Input
would this correct the issue?

Thank You,
Loren Dorez
FromMe
ToLoren Dorez
SubjectRe: Saving Multiple Forms to a Cookie
Date13 February 2007 09:07
Loren,

>     formstrings[i] =
> getFormElement(document.forms.elements[i].value);
>
> Is this why the check boxes arent saved when i reload
> the form?

Yes. Your approach is too simplistic. There are different things that you
need to do to restore a form to its former state, depending on what type of
input you are dealing with - you can check the input's type by reading the
.type property:

text, textarea, password [, non-button Web Forms 2.0 input types]
  read/write the .value property
checkbox, radio
  read/write the .checked property
select-one
  read/write the .selectedIndex property
select-multiple
  read/write the .selected property for every option

My script already deals with these for you (except WF2 inputs, which I doubt
you will be using).
[Ed. it now also copes with WF2 inputs]


Tarquin
FromLoren Dorez
ToMe
SubjectRe: Saving Multiple Forms to a Cookie
Date14 February 2007 02:06
Tarquin,

OK thank you i will try taking your and taking the
variable and loading it into an array and load the
array into the cookie as this should solve my issues..
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.