Email conversation
From | Michal |
To | Me |
Subject | Using the form recall function |
Date | 8 March 2006 12:19 |
Hoi there,
First of all great site! with some great scripts! You had just what i was
looking for for a long time...
I found this script on your site
http://www.howtocreate.co.uk/jslibs/script-saveformvalues its the form
recall script.
The way that i would like to use the script is like they do on
[URL] you select an country press a button and it saves it
in a cookie
I have tried it all. in my body i have put the onload then called for the
cookie with also your cookie script but that didnt work. Is there any way
you know how i could make this posible
Thanks
From | Me |
To | Michal |
Subject | Re: Using the form recall function |
Date | 8 March 2006 13:01 |
Michal,
> The way that i would like to use the script is
> you select an country press a button and it saves it
> in a cookie
1. download both the cookie and saveFormValues scripts:
http://www.howtocreate.co.uk/jslibs/script-cookie
http://www.howtocreate.co.uk/jslibs/script-saveformvalues
2. use <script type="text/javascript" src="whatever.js"> tags to put them
both in the head of the page
3. have an onsubmit handler that saves the choice when the form is
submitted
4. use a checkbox input to say if the value should be saved (exclude the
checkbox when saving).
5. have an onload handler that recovers the form
Sample:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="cookie.js"></script>
<script src="saveFormValues.js"></script>
<script type="text/javascript">
function doRecovery() {
recoverInputs(
document.forms.myForm,
retrieveCookie('countrychoice'),
false,
FS_EXCLUDE_IDS,
'remember'
);
}
function doSave(oForm) {
if( !oForm.remember.checked ) { return; }
setCookie(
'countrychoice',
getFormString(oForm,false,FS_EXCLUDE_IDS,'remember')
);
}
</script>
<title>Save Choice</title>
</head>
<body onload="doRecovery();">
<form method="get" name="myForm" action="" onsubmit="doSave(this);">
<p>Choose a country: <select name="country">
<option value="uk">United Kingdom</option>
<option value="nl">Netherlands</option>
</select> <input type="submit" value="Go"></p>
<p><label for="remember">
<input name="remember" id="remember" type="checkbox" value="1">
Remember my choice.</p>
</form>