Form che ricorda i dati. Per testarla inserire dei valori nei campi, chiudere la finestra, riaprirla e posizionarsi con il mouse sui campi precedentemente compilati.
<HTML>
<HEAD>
<TITLE>A Form That Remembers</TITLE>
<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); }
</HEAD>
<BODY BGCOLOR = "#FFFFFF">
Per testarla inserire dei valori nei campi, chiudere la finestra, riaprirla e posizionarsi con il mouse sui campi precedentemente compilati<br>
<FORM ACTION = "Pagine ch eprocessa il form ">
<P>
Your Name: <INPUT TYPE = "TEXT" NAME = "yourname" onFocus = "getValue(this)" onBlur = "setValue(this)">
<P>
Your ID: <INPUT TYPE = "TEXT" NAME = "yourid" onFocus = "getValue(this)" onBlur = "setValue(this)">
<P>
Your Password: <INPUT TYPE = "TEXT" NAME = "yourpassword" onFocus = "getValue(this)" onBlur = "setValue(this)">
</FORM>
</BODY>
</html>