...

View Full Version : How to dyamically change content on page?



amir103
12-10-2006, 06:11 PM
How can I , for example, replace an image with another image, or some text, Or change the information in some text. But All this has to happen dynamically and without refreshing the page. How can this be achieved best?

1212jtraceur
12-10-2006, 10:53 PM
I would use the Document Object Model (http://en.wikipedia.org/wiki/Document_Object_Model). Example:

JavaScript:


function changeText()
{
var newText = document.createTextNode('This is the new text.');
var container = document.getElementById('textDiv');
container.replaceChild(newText, container.firstChild);
}


XHTML:


<div id="textDiv" onclick="changeText()">
This is the old text.
</div>


Note that the change need not be user-prompted. You can call changeText() upon window.onload or whe(r|n)ever you want...

amir103
12-11-2006, 02:34 AM
thanks man: exactly what I was looking for, but how could I make a timer instead of the onclick function?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum