// Script starts here.
// View a sample form demo.
/*
This script uses the saveForm() function to save a form's entries for 60 days.
The autoFill() function can enter the saved values on future visits.
Note: These functions apply only to text inputs and single-choice selectors.
Run the save function with the form object to save as its argument.
e.g. onSubmit="saveForm(this);" would save the current form's data at submission.
This function can also save only a form slice.
e.g. "saveForm(document.form_name, 5, 31);" would save the 6th to 32nd fields.
Run autoFill() with the form object to fill-in as its argument.
e.g. onLoad="autoFill(document.form_name);" would fill form form_name.
Important! This entire script must be pasted between script tags in the document head.
*/
function stopError() {return true;}
window.onerror=stopError;
// Comment out the above line to show script errors.
var formCookieId = 'form_save';
// Specifies the cookie name. Use different names for multiple pages.
function dbstream(a1) {
var db = '';
for (var k in a1) if (a1[k] || a1[k] == '') db += '&' + escape(k) + '=' + escape(a1[k]);
return db.substring(1);
}
function dbparse(a1) {
var db = {};
if (!a1) return db;
a1 = a1.split('&');
for (var k in a1) {
k = a1[k].split('=');
db[unescape(k[0])] = unescape(k[1]);
}
return db;
}
function setcookie(a1,a2,a3) {
if (!a1) return;
function daystring(A1) {
var time = new Date();
time.setTime(time.getTime() + (86400000 * A1))
return time.toGMTString();
}
document.cookie = escape(a1) + '=' + escape(a2) + (a3 &&
( isNaN(a3.expires) ? '' : '; expires=' + daystring(a3.expires) ) +
( a3.path ? '; path=' + a3.path : '' ) +
( a3.domain ? '; domain=' + a3.domain : '' ) +
( a3.secure ? '; secure' : '' ) || '');
}
function getcookie(a1){
a1 = escape(a1);
var tie = ' ' + document.cookie;
var sta = tie.indexOf(' ' + a1 + '=');
if (sta == -1) return null;
var end = tie.indexOf(';',sta);
return (end != -1) ? unescape(tie.substring(sta + 2 + a1.length,end)) : unescape(tie.substring(sta + 2 + a1.length));
}
function killcookie(a1) { setcookie(a1,'',{ expires:0 }); }
function tiecookie(a1,a2,a3) {
if (!a1 || !a2) return;
setcookie(a1,dbstream(a2),a3);
}
function untiecookie(a1) {
var ties = getcookie(a1);
if (!ties && ties != '') return null;
return dbparse(ties);
}
function saveForm(Form, skipTo, stopAt) {
var allLength = Form.length;
var dataStore = new Object();
dataStore.textFields = new Object();
dataStore.popuplists = new Object();
for (var i=skipTo||0; i<(stopAt||allLength); i++) {
var thisField = Form.elements[i];
var fieldType = thisField.type;
var fieldName = thisField.name;
if (!fieldName) continue;
if (fieldType == 'text') {
dataStore.textFields[fieldName] = thisField.value;
continue;
}
if (fieldType == 'select-one') {
dataStore.popuplists[fieldName] = thisField.selectedIndex;
}
}
dataStore.textFields = dbstream(dataStore.textFields);
dataStore.popuplists = dbstream(dataStore.popuplists);
tiecookie(formCookieId, dataStore, { expires:60 });
}
function autoFill(Form) {
var allLength = Form.length;
var dataFound = untiecookie(formCookieId);
if (dataFound &&
confirm('This form has been filled in previously.\nWould you like to enter it automatically?')
) {
dataFound.textFields = dbparse(dataFound.textFields);
dataFound.popuplists = dbparse(dataFound.popuplists);
for (var i=0; i<allLength; i++) {
var thisField = Form.elements[i];
var fieldType = thisField.type;
var fieldName = thisField.name;
if (!fieldName) continue;
if (fieldType == 'text' && dataFound.textFields[fieldName]) {
thisField.value = dataFound.textFields[fieldName];
continue;
}
if (fieldType == 'select-one' && dataFound.popuplists[fieldName]) {
thisField.selectedIndex = dataFound.popuplists[fieldName];
}
}
}
}
/*
Questions or Comments? Email them to the author: "Joseph K. Myers" <e_mayilme@hotmail.com>.
Include all pertinent information. A response is not guaranteed.
Free use for any non-restricted type website is granted.
Do not remove this comment section.
Script Author: Joseph K. Myers <e_mayilme@hotmail.com>
Script Source: MyersDaily <https://www.angelfire.com/yt/jmyers/>
# |- Script Specifications -| #
# language: javascript1.2 Version: 2.0.0 Release Date: April 12, 2000
*/
// End of script.
|