Snap Builder Public Codes Library
Snap | Generators | Login | Browse | Search | Enter Code | Export Snap Builder Public Codes Library

 

Category: Javascript Codes Library >> Cookies >> Cookie Remember Form Data


Code Snippet </> Info


Snippet Name: Cookie Remember Form Data

Description: A form that remembers exactly what the visitor has entered in to field boxes... even if not submitted, through cookie capture.

Compatible Browsers:
Chrome BrowserFirefox BrowserInternet Explorer BrowserOpera BrowserSafari Browser


Example: View Code Demo

Note:

Author: SnapBuilder <snippets@snapbuilder.com>

Last Modified: 2015-08-26 22:58:46

Language: javascript

Highlight Mode: javascript

Copy Codes: Use Free Notepad ++
Bookmark and Share

Snap HTML Code Editor:
Paste the source code, make changes and instantly see it in live preview.
Snap HTML Code Editor


  About Copying
Copied To Clipboard!

<html> <head> <title>Cookie Remember Form Data Javascript Code Snippet</title> <script> <!-- /* Begin Cookie Remember Form Data == This Script Free To Use Providing This Notice Remains == == This Script Has Been Found In The http://snapbuilder.com Free Public Codes Library == == NOTICE: Though This Material May Have Been In A Public Depository, Certain Author Copyright Restrictions May Apply == == Creative Commons License == */ // Use this function to retrieve a cookie. function getCookie(name){ var cname = name + "="; var dc = document.cookie; if (dc.length > 0) { begin = dc.indexOf(cname); if (begin != -1) { begin += cname.length; end = dc.indexOf(";", begin); if (end == -1) end = dc.length; return unescape(dc.substring(begin, end)); } } return null; } // Use this function to save a cookie. function setCookie(name, value, expires) { document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString()); } // Use this function to delete a cookie. function delCookie(name) { document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/"; } // Function to retrieve form element's value. function getValue(element) { var value = getCookie(element.name); if (value != null) element.value = value; } // Function to save form element's value. function setValue(element) { setCookie(element.name, element.value, exp); } var exp = new Date(); exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31)); //--> </script> </head> <body> <center><h1>A Form that Remembers</h1></center> <p>Type whatever you like in the boxes below, click outside the box, reload the page, and try to type the details again.<br /> This script uses cookies, so if you have them disabled it will of course not work.</p> <form> <table> <tr> <td>Your Name: </td> <td><input type="text" name="yourname" onfocus="getValue(this)" onblur="setValue(this)"></td> </tr> <tr> <td>Your ID: </td> <td><input type="text" name="yourid" onfocus="getValue(this)" onblur="setValue(this)"></td> </tr> <tr> <td>Your Password: </td> <td><input type="text" name="yourpassword" onfocus="getValue(this)" onblur="setValue(this)"></td> </tr> </table> </form> <br /><br /> <div id="snippet"> [ This code example from <a href="http://snapbuilder.com/code_snippets/copy_code_snippet_63.html">Cookie Remember Form Data</a> page. ] </div> </body> </html>


[ Snippet Options ]

 

© 2002 -  Snap Builder Public Codes Library