Email conversation
From | Ben Marks |
To | Me |
Subject | Save Form Values Script |
Date | 31 March 2006 21:19 |
I am interested in using your 'Save Form Values' script on my site, for a
checklist type thing so when someone gets a certain avatar they can tick it
off, and then it will load up again when they revisit to tick off another.
I am not sure how to actually use your script I got the:
Inbetween the <head> tags, put:
<script src="PATH TO SCRIPT/cookie.js" type="text/javascript"
language="javascript"></script>
But have no idea where to go from there, where do you put the 'store a
cookie' code?
Regards,
Ben
From | Me |
To | Ben Marks |
Subject | Re: Save Form Values Script |
Date | 1 April 2006 13:11 |
Ben,
> I am interested in using your 'Save Form Values' script on my site,
> for a checklist type thing so when someone gets a certain avatar they
> can tick it off, and then it will load up again when they revisit to
> tick off another. I am not sure how to actually use your script
Put this in the head:
<script src="PATH TO SCRIPT/saveFormValues.js"
type="text/javascript"></script>
<script src="PATH TO SCRIPT/cookie.js" type="text/javascript"></script>
(remember to change 'PATH TO SCRIPT' to wherever you have stored the scripts
on your own server)
Then you need to store the cookies. At a guess, you will be using a standard
Web page form, so you should be able to use the onunload and onload events:
<script type="text/javascript">
window.onunload = function () {
setCookie(
'formInputs',
getFormString( document.forms.myForm, true ),
604800
);
};
window.onload = function () {
recoverInputs(
document.forms.myForm,
retrieveCookie( 'formInputs' ),
true
);
};
</script>
If other scripts are using these events, you will need to combine their
event handler functions. Remember to change the 'myForm' to match the name
you have given your form.
Note also that if your form is ever likely to change length (if you will add
or remove avatars, for example), then this script will not cope with that
change, and it is not appropriate to use this script.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/