»
EnglishFrenchVietnamese

Print - Remember Form Data - JavaScriptBank.com

Full version: jsB@nk » Cookie » Remember Form Data
URL: https://www.javascriptbank.com/a-form-that-remembers.html

Remember Form Data © JavaScriptBank.comType whatever you like in the boxes, click outside the box, reload the page, and try to type the details again. This JavaScript uses cookies, so if you have them disabled it will of course not work.

Full version: jsB@nk » Cookie » Remember Form Data
URL: https://www.javascriptbank.com/a-form-that-remembers.html



JavaScript
<SCRIPT language=JavaScript><!--// 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><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<FORM><TABLE>  <TBODY>  <TR>    <TD>Your Name: </TD>    <TD><INPUT onblur=setValue(this) onfocus=getValue(this)   name=yourname></TD></TR>  <TR>    <TD>Your ID: </TD>    <TD><INPUT onblur=setValue(this) onfocus=getValue(this) name=yourid></TD></TR>  <TR>    <TD>Your Password: </TD>    <TD><INPUT onblur=setValue(this) onfocus=getValue(this)     name=yourpassword></TD></TR></TBODY></TABLE></FORM><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->