473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SetTimeout not working

Hi

The below pasted code is my attempt to get the text of a span to change
every second.

However, it seems to just set the text of the span to be the last item
in the array.

Can anybody help?

Many thanks in advance

Daz

<script language="javascript" type="text/jscript">

function DoWait()
{

vAirlines = new Array("Wind", "Rain", "Fire", "Earth");

for (i=0;i<vAirlines.length-1;i++)
{
string = "document.getElementById(\"spAirlineCount\").inner HTML = \""
+ vAirlines[i] + "\"";

setTimeout(string, 1000);
}
}

DoWait();
</script>

<span id="spAirlineCount">000</span>

Aug 14 '06 #1
3 3772
wrote on 14 aug 2006 in comp.lang.javascript:
setTimeout(string, 1000);
a string is not a command in the sense of setTimeout
for (i=0;i<vAirlines.length-1;i++)
{
string = "document.getElementById(\"spAirlineCount\").inner HTML = \""
+ vAirlines[i] + "\"";

setTimeout(string, 1000);
}
}
Anyway, your 4(?) strings would execute at once,
being all 1 second after the for loop.
so what is the sense?

A setTimout() is NOT a wait() function found in other languages.

Try:

========================
<div id='spAirlineCount'>-----</div>

<script type='text/javascript'>

var vAirlines = new Array("Wind", "Rain", "Fire", "Earth");
var theDiv = document.getElementById('spAirlineCount');
var i=0;
setTimeout('showOne()',1000);

function showOne(){
theDiv.innerHTML = vAirlines[i++];
if (i < vAirlines.length)
setTimeout('showOne()',1000);
};

</script>
=========================
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 14 '06 #2
Hi Evertjan

I was just coming to that conclusion after looking at this
http://www.jsmadeeasy.com/javascripts//Text
Animations/text_rotation_userBrowDetection/text_rotation_userBrowDetection.htm

Many thanks for your help.

Darren
Evertjan. wrote:
wrote on 14 aug 2006 in comp.lang.javascript:
setTimeout(string, 1000);

a string is not a command in the sense of setTimeout
for (i=0;i<vAirlines.length-1;i++)
{
string = "document.getElementById(\"spAirlineCount\").inner HTML = \""
+ vAirlines[i] + "\"";

setTimeout(string, 1000);
}
}

Anyway, your 4(?) strings would execute at once,
being all 1 second after the for loop.
so what is the sense?

A setTimout() is NOT a wait() function found in other languages.

Try:

========================
<div id='spAirlineCount'>-----</div>

<script type='text/javascript'>

var vAirlines = new Array("Wind", "Rain", "Fire", "Earth");
var theDiv = document.getElementById('spAirlineCount');
var i=0;
setTimeout('showOne()',1000);

function showOne(){
theDiv.innerHTML = vAirlines[i++];
if (i < vAirlines.length)
setTimeout('showOne()',1000);
};

</script>
=========================
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 14 '06 #3
JRS: In article <11**********************@m73g2000cwd.googlegroups .com>
, dated Mon, 14 Aug 2006 07:43:47 remote, seen in
news:comp.lang.javascript, Da**************@gmail.com posted :
>The below pasted code is my attempt to get the text of a span to change
every second.
...
setTimeout(string, 1000);
Other considerations apart, if you want it to change exactly once every
second in every browser you will need to change that second argument, to
allow for timing overheads and rounding.

See <URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>.

PS - Are there combinations of browser and OS for which Tock() does not
always show N.1 seconds plus a varying bit, or for which Tick() does
show that?

function DP3(T) { return String(T).replace(/(\d\d\d)$/, '.$1') }

function Tick() { var D = new Date()
setTimeout("Tick()", 1000) // Drifty
DynWrite("ic", DP3(D.getTime())) }

function Tock() { var D = new Date()
setTimeout("Tock()", 1100-D%1000) // Synced
DynWrite("oc", DP3(D.getTime())) }

OP : read the newsgroup FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: oliver | last post by:
Hi, the structure of my source code is like this: <script> C = function(){ //some initialization } C.prototype.start = function{ //some action
2
by: Athanasius | last post by:
Could someone shed some light as to why the following setTimeout function will not work on the Mac IE5.2? It does however work on PC(Forefox,Netscape,IE) & Mac(Safari,Firefox). Here is the script,...
3
by: jshanman | last post by:
I've created a "Play" button for my timeline that uses the Google Maps API. It basicly scrolls the timeline x interval every y milliseconds. The problem is the browser responds slowly even after...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
28
by: Andre | last post by:
Hi, Does anyone know whether the ECMA, or an other standard document, specifies a maximum for the value that can be pass to the setTimeOut() function in Javascript? Andre
1
by: James Black | last post by:
I am trying to fade a word out, so after 5 seconds then every 1/4 sec it should fade by a small amount, until it is gone. This works fine in Firefox, but IE never calls the function that...
17
by: blueapricot416 | last post by:
This is a very basic question -- but I can't find the answer after looking for 20 minutes. If you code something like: function set_It() { setTimeout('Request_Complete("apple", -72)',5000) }...
4
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a...
7
by: Martin | last post by:
Can I have two setTimeouts running at the same time - with two different intervals? I want to start one timer and, before it times out, start another one I've tried this and they seems to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.