DelphiFAQ Home Search:

Dynamically change a normal text statement on a html page

 

comments1 comments. Current rating: 5 stars (1 votes). Leave comments and/ or rate it.

Question:

I want to display a kind of countdown on my web page with a redirect happening once 0 is reached.
How can I update the counter without reloading the page every time?

Answer:

You need to define a
section or even use a header. Give this section a unique ID, use javascript to get a reference to the element and use the .innerHTML property to update the text.

To implement the countdown, you need to set a timer.
The example shows this and uses setTimeout for the timer.

<script language="JavaScript">
<!--
var iTime=5;
function update() {
var txt = 'Will update progress ';
if (iTime>1) { txt = txt + 'in ' + iTime + ' seconds.'; }
else {
  if (iTime==1) { txt = txt + 'in one second.'; }
  else { txt = txt + 'now.'; }
}
document.getElementById("cnt").innerHTML = txt;
iTime=iTime-1;
if(iTime>=0) { ID=window.setTimeout("update();",1000); }
else { document.location.href="/request?70"; }
} 
// -->

</script>
</head>
<body onload="update()">

<div name=cnt id=cnt>Will update progress in 5 seconds.</div>

Comments:

2007-04-22, 01:10:09
anonymous from Iran in Chahar Mahall va Bakhtiari, Iran  
rating
I used it very simply.

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.