Mega Code Archive

 
Categories / JavaScript DHTML / GUI Components
 

Periodically Updating the Text Displayed by an HTML Element

/* Mastering JavaScript, Premium Edition by James Jaworski  ISBN:078212819X Publisher Sybex CopyRight 2001 */ <html> <head> <title>Replacing Text</title> <script language="JavaScript"> var msgIX = 0 var msgs = new Array(  "Notice anything different?",  "The text you are looking at has changed.",  "This is a handy way of sending messages to your users." )     function scrollMessages(milliseconds) {  window.setInterval("displayMessage()", milliseconds) } function displayMessage() {  if(document.getElementById != null) {   var heading = document.getElementById("scrollme")   heading.firstChild.nodeValue = msgs[msgIX]  }else{   if(navigator.appName == "Microsoft Internet Explorer") {    var heading = document.all.item("scrollme")    heading.innerText = msgs[msgIX]   }  }  ++msgIX  msgIX %= msgs.length } </script> </head> <body onload="scrollMessages(2000)"> <h1 align="center" id="scrollme">Watch this text very carefully!</h1> </body> </html>