Michal

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromMichal
ToMe
SubjectUsing the form recall function
Date8 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
FromMe
ToMichal
SubjectRe: Using the form recall function
Date8 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>



Hope this helps.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromMichal
ToMe
SubjectRe: Using the form recall function
Date9 March 2006 16:03
Thnx im going to try it out tommorow.

But does it no redirect me atomaticly to the right page or do i have to make
a phpscript wich checks the cookie and the redirects you to the correct
page?
FromMe
ToMichal
SubjectRe: Using the form recall function
Date9 March 2006 16:15
> But does it no redirect me atomaticly to the right page or do i have to make
> a phpscript wich checks the cookie and the redirects you to the correct
> page?

Use a PHP script that checks on the value of $_GET['country'] and redirects
to the right page.

The simple reasoning being that you should never rely on JavaScript to
provide your navigation.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.