DelphiFAQ Home Search:
General :: Programming :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Dynamically change a normal text statement on a html page


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?


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;
 if(iTime>=0) { ID=window.setTimeout("update();",1000); }
 else { document.location.href="/request?70"; }
 // -->
 <body onload="update()">
 <div name=cnt id=cnt>Will update progress in 5 seconds.</div>

Generated 8:01:44 on Jun 2, 2020