Closed Thread Icon

Topic awaiting preservation: Page has been modified (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=24185" title="Pages that link to Topic awaiting preservation: Page has been modified (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Page has been modified <span class="small">(Page 1 of 1)</span>\

 
Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 11-25-2004 14:08

Hi,
The following code I've wrote enables to identify modifications on page/form.

Enjoy it

code:
/**
* The following module enables to verify whether a page has been modified.
* In order to activate the module, call the _CapturePageState() function after the page loaded (last thing)
* and before submitting the page, you can verify if the page modified by calling the _isPageStateModified() function.
* Limitations: the module is not working well with dynamic content (adding removing content).
*/
var _objState = new Array();

function _CapturePageState(){
_objState = new Array();
var oElms = document.getElementsByTagName("*");

// Build a list of all the items and their values
for(var i=0; i<oElms.length; i++){
var o = oElms[i];
if(o.name && o.name.length > 0){
var item = o.name + "_" + o.value;
if(o.checked){
item += "_checked";
}
if(o.disabled){
item += "_disabled";
}
_objState[item] = "1";
}
}
}
// for checking a specific form, pass the form object as parameter
function _isPageStateModified(oBaseElem){
if(!oBaseElem) oBaseElem = document;
var oElms = oBaseElem.getElementsByTagName("*");

for(var i=0; i<oElms.length; i++){
var o = oElms[i];
if(o.name && o.name.length > 0){
var item = o.name + "_" + o.value;
if(o.checked){
item += "_checked";
}
if(o.disabled){
item += "_disabled";
}
if(!_objState[item]){
return true;
}
}
}
return false;
}



(Edited by Yossi Admon on 11-25-2004 14:16)

(Edited by Yossi Admon on 11-25-2004 14:34)

BillyRayPreachersSon
Bipolar (III) Inmate

From: London
Insane since: Jul 2004

posted posted 11-28-2004 11:19

Not bad, but a few things to be wary of. If I had two elements thus:

Name: "item_1_2"
Value: ""

Name "item_1"
Value: "2_"

Then your code would fail, as the string used to delve into the associative array for both would be "item_1_2_", so the second would always overwrite the first.

Have you considered also looking into the defaultValue attribute for form fields? It provides an easy way to tell if the value has been changed since the page was delivered.

Dan

« BackwardsOnwards »

Show Forum Drop Down Menu