tags:

views:

31

answers:

2

Hi , I need to check whether document element value is changed after perticular operation using java script

My requirment is There is document elements contains default values after changing perticular date element there is some ajax opertion document elements values changes.

This return all the doucument element then after i going to store it into array

document.body.getElementsByTagName('*');

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

Please help.

+4  A: 

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);
}
Jonathan Sampson
how to serialized data?
Yashwant Chavan
need to do this plain java script not using jquery
Yashwant Chavan
Yashwant, I've updated my solution to use pure javascript.
Jonathan Sampson
A: 

Hi Yashwant

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.

Yo Momma