Hi,

I am working on the application in which Ajax, JSP, Javascript and html is used in UI part. We have our own UI frame work in which we update the page through AJAX. i.e. Initially page is loaded and later on we request to AJAX to update that particular page. But here page is updated without refreshing or reloading.

Requirement: Requirement is when the page is updated I have to make one button disable on that page.

Problem: I can make the button disable on 'onload' event of that page which get calls when the page is refreshed or reloaded. But as ajax update the page without refreshing/reloading the page, I am not able to get the event 'onload' and so I can not call the method which disable that particular button.

Is there any other way to work ? or

Is there any function of javascript which will be called automatically once the page is updated with refreshing?

Let me know if you need more information on this,

Thanks
Chandan

Am not sure if this wil solve the issue. But this may come in handy...

This will allow you to add function() calls once the page is loaded!
It's ideal for use in scripts that may be executing along side other scripts that have already been registered to execute once the page has loaded.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Some Title</title>
<script type="text/javascript">
<!-- BEGIN HIDING

function newLoadEvent( _function ) 
{ var _onload = window.onload; 
if ( typeof window.onload != 'function' ) 
{ window.onload = _function; } else { window.onload = function() {  
if ( _onload ) { _onload();  }  _function(); 
  } 
 } 
} 

/* Name of some function()
 to run on page load *///---->
newLoadEvent( example ); 
function example()
{ document.getElementById('sample').innerText = 'Hello World!';
}


/* More function() to run on page load *///----->
newLoadEvent( function() { /* More code to run on page load */ alert('Hello World!'); 
} );


/* The 3rd function() to run on page load and so on... *///---->
newLoadEvent( function() {  document.getElementById('sample1').innerHTML = document.title; 
} );

// DONE HIDING -->
</script>
</head>
<body>
<p>
<span id="sample"></span>
<br />
<span id="sample1"></span>
</p>
</body>
</html>
Member Avatar for langsor

Hi,

It's true that most elements do not support the onload event ... the window does and images do too.

I have yet to find a browser that loads content other than top to bottom, so you could effectively include a tiny-invisible-gif image at the very end of you dynamically loaded content and give it an onload event to call the javascript function that disables your button.

Hope this helps

<html>
<head>
<script type="text/javascript">
function loaded ( target ) {
  alert( target.parentNode.id );
}
</script>
</head>
<body>
  <div id="test">
    <img src="one.gif" onload="loaded(this)" />
  </div>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.