gibney.org
:
Technology
:
Javascript
:
Includes
:
PersistentFormdata2
(Entry Nr. 1197, by user 39 |
edit
)
/* www.gibney.org PersistentFormdata */ // <script src="http://javascript.en.gibney.org/saveform.js" type="text/javascript"></script> // <textarea class="code_area"> /* Script by Gibney-Enterprises include this script in a HTML-Page with a Form. Fill the form and press ctrl+shift+p to get a url for the current page with your values in input-fields and textareas */ ge_persistentFormdata_forms=Array(); function ge_persistentFormdata_KeyPress(e) { var code; if (!e) e = window.event; if (e.which) { code=e.which; } else { code=e.keyCode; } if (e.ctrlKey && e.shiftKey) { if(code==80) // 80=p as persistent { ge_persistentFormdata_MakePersistent() return false; } } } function isInArray(array, value) { for (var i=0; i<array.length; i++) if(array[i]==value) return true; return false; } function ge_persistentFormdata_MakePersistent() { var parameters=''; if(ge_persistentFormdata_forms.length==0) ge_persistentFormdata_forms=document.forms; for (var f=0; f<document.forms.length; f++) { var form=document.forms[f]; if(!isInArray(ge_persistentFormdata_forms, form)) continue; var elementcount=form.elements.length; for (var e=0; e<elementcount; e++) { if (form.elements[e].name=='') continue; if (parameters.length>0) parameters+='&'; // parameters+=form.elements[e].name; parameters+='gePF_'+f+'_'+e; parameters+='='; parameters+=encodeURIComponent(form.elements[e].value); } } window.location.hash=encodeURIComponent(parameters); } function ge_persistentFormdata_LegacyCheck() { if (window.location.query.length>0) { var parameters=window.location.query.substr(1).split('&'); for (var p=0; p<parameters.length; p++) { if (parameters[p].substr(0,5)=='gePF_') { alert('This URL contains an outdated persistentformdata-Format. Please use # instead of ?.'); break; } } } } function ge_persistentFormdata_Restore() { ge_persistentFormdata_LegacyCheck(); if (window.location.hash.length>0) { var parameters=window.location.hash.substr(1).split('&'); var parametercount=parameters.length; for (var p=0; p<parametercount; p++) { var temp=parameters[p].split('='); if (temp[0].substr(0,5)!='gePF_') continue; // this i not a persistentForm-Field var name=temp[0]; var value=decodeURIComponent(temp[1]); temp=name.split('_'); document.forms[temp[1]].elements[temp[2]].value=value; } } } document.addEventListener('keydown', ge_persistentFormdata_KeyPress, false); window.addEventListener('load',ge_persistentFormdata_Restore); //
Create a new entry at this position