See also: storeData |
Function used to retrieve data from the cookie set by the JSV_storeData function and sets the values in the corresponding form fields.
JSV_retrieveData(formName)
n/a
The retrieveData function returns true if data was found; false otherwise.
The retrieveData function uses the following argument.
Argument | Description |
formName | The name of the form. This name is used for storing the cookie and when the data is retrieved. |
The JSV_storeData function allows you to exclude any field or fields from being saved in the cookie, e.g., a credit card number and expiration date. This feature is useful for fields that may contain sensitive information or when it does not make sense to retain the data, such as a product number on an order form.
The JSV_storeData
and JSV_retrieveData
functions can handle all types of text fields
(hidden, password, text and textarea),
selection lists (single and multiple),
checkboxes and radio buttons.
The retrieveData function was written by Mike Hall at BrainJar.
The JSV_storeData function loops through the form fields and creates a deliminated string of each field name and value, skipping any field name that appears in the exclusion list. This string is then stored as a cookie with the given name and expiration date. The deliminators used are non-printable characters so there will be no conflict with the data.
JSV_retrieveData
function reads the named cookie and parses the field
name/value pairs. It then looks for a form with the same name on the page and
sets the values according to what is stored in the cookie.
For text fields, this is easy. It simply copies the value. But for radio buttons, check boxes and selection lists, the function must look at each available option for that particular field. If one matches the value stored, it marks it as checked or selected.
Use the onSubmit
method of the FORM
tag to call the
JSV_storeData
function.
<form name="myForm" action="http://www.xyz.com/cgi-bin/order.cgi" method="post" onsubmit="return JSV_storeData(this.name, 7);">
To load the data back into the form, call the
JSV_retrieveData
function
passing it the name of the form.
This function will retrieve the cookie and repopulate the
named form. You might call the JSV_retrieveData
function using the onLoad
method of the BODY
tag.
<body onload="JSV_retrieveData('myForm');">
Or you can provide a link or button on the Web page
that will call the JSV_retrieveData
function when clicked.
This gives the user an option whether they would like to restore the data or not.
This would be good for setting user profiles or defaults.
<a href="#" onclick="JSV_retrieveData('myForm'); return false;">Load Defaults</a>
Note that if you change a form field's name or the values of a radio, checkbox or selection list those fields will not be reloaded on the user's next visit. Likewise, if you change the form name, any previous saved data will be rendered useless. This can be done if you need to rework the form and want a fresh start.
n/a
(View source to see the code for this example)
Copyright © 2000 Roaring Fork Software. All rights reserved.