Home
Form effects
Here
|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
FF1+ IE5+ Opera 7+
Recall Form Values script II Author:
Description: You've probably seen this feature inside the comment forms of blogs, where a checkbox lets you specify whether to remember the values of certain text fields and recall them later. Well, this script adds such a feature to any form! The script operates like so:
Demo: Check the checkbox to remember values entered into the name and email fields when the form is submitted: Step 1: Add the below script to the HEAD section of your page containing the form: The above script references an external .js file. Download "formretain2.js" (by right clicking and selecting "Save As"), and upload to the directory where your webpage resides. Step 2: To use this script on certain text fields of a form, take a look at the below sample HTML: <form id="demoform">
<input id="woot" type="text" value="" /><br/>
<input id="woot2" type="text" value="" />
<input type="submit" value="submit" /><br />
<input type="checkbox" id="persistbox" /> Remember my info?
</form>
<script type="text/javascript">
var f1=new rememberForm("demoform") //create instance of script referencing form "demoform"
f1.persistfields("woot", "woot2") //specify the text fields "woot" and "woot2" to be remembered
f1.addtoggle("persistbox") //specify the checkbox "persistbox" as the " toggle box". (optional).
</script>
Simply create an instance of the script and use either the ID or name of the form in question (ie: "demoform") as the sole parameter. Then, specify the text fields within this form that should be remembered, where "woot" for example is the ID or name of the text field. Finally, if you've defined a checkbox inside your form as the user "toggle box", specify this checkbox's id/name inside the script. With the above done, the text fields "woot" and "woot2" will be remember if the user checks the checkbox "persistbox" when submitting the form. If you have more than one form on the same page you wish to add this script to, just repeat the above using each form's unique IDs or names in each case. FAQs
And that's it. Oh yes, and if for whatever reason you wish to clear a user's browser cookie of any saved values down the road for a particular form, you can call the internal method: //scriptinstance.clearcookie() f1.clearcookie() to do so. In the above case, the form referenced by "f1" will have its saved values flushed from the user's cookie as soon as the above line is run. This may be useful if you've made dramatic changes to a form and don't want an legacy values to be misplaced into the wrong text fields. Enjoy! |