开发者

Compare document element values changes

I need to check whether document element value is changed after particular operation using Javascript.

My requirements are:

  • There is document elements contains default values after changing particular date element .
  • There is some Ajax operation document elements values changes.

This returns all the document element then after I'm going to store it i开发者_如何学Gonto array

document.body.getElementsByTagName('*');

I want to find out which element values changes after request using java script


I would suggest you serialize the elements and values before the operation takes place, and then compare the serialized data to the live elements following the process.

Serializing can be very easy:

function serialize() {
  var output = "";
  for (var i = 0; i < document.myForm.elements.length; i++) {
    name   = document.myForm.elements[i].name;
    value  = document.myForm.elements[i].value;
    output = output + name + "=" + value + "&";
  }
  alert(output);
}


With ajax you have two types of calls, Asynchronous and Synchronous calls in javascript, using GetXmlHttpObject(). When you do the "open" call, the third parameter sets the Sync as a boolean. I.E:

     xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var querystring_variables = create_request_string(theform);
    var url= scriptPage + "?" + querystring_variables + "&time=" + timestamp;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);

True means means synchronous false means asynchronous.

Basically your ajax call should populate a div or text box on you webpage. If you do the call asynchrounously and do the a call to check the value returned, the javascript will run too early and the value read by your javascript call will be returned as nothing.

If you do it Synchronously, the javascript function to read the value will wait for the ajax to return a value before executing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜