468,285 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,285 developers. It's quick & easy.

Why it does not give me timeout?

QA
Array.prototype.shuffle= function(times){
var i,j,t,l=this.length;
while(times--){
with(Math){
i=floor(random()*l);j=floor(random()*l);}
t=this[i];this[i]=this[j];this[j]=t;
}
return this;
}
var st=[
"http://javascript.internet.com/img/image-cycler/01.jpg",
"http://javascript.internet.com/img/image-cycler/02.jpg",
"http://javascript.internet.com/img/image-cycler/03.jpg",
"http://javascript.internet.com/img/image-cycler/04.jpg"
]
st.shuffle(200);

function donothing () {return true;}

for(j=0;j<st.length;j++){

setTimeout('donothing()', 2000);
//rImage.src = st[j];
//rText.value = st[j];
document.write (st[j]);
}

**************************************
I want to display them every 2 second. After everything is displayed it then
stops.
But it does not give me the 2s delay. It displays everything once.
Jul 23 '05 #1
3 1220
"QA" <QA@alexa.com> skrev i melding
news:7%*****************@news04.bloor.is.net.cable .rogers.com...
I want to display them every 2 second. After everything is displayed it then stops.
But it does not give me the 2s delay. It displays everything once.


Try using setInterval.
setTimeout is a method for setting a one shot timer.

Oeyvind
http://home.online.no/~oeyvtoft/ToftWeb/
Jul 23 '05 #2
QA wrote on 10 sep 2004 in comp.lang.javascript:

function donothing () {return true;}

for(j=0;j<st.length;j++){

setTimeout('donothing()', 2000);
document.write (st[j]);
}

**************************************
I want to display them every 2 second. After everything is displayed
it then stops.
But it does not give me the 2s delay. It displays everything once.


Because you are doing nothing once.

If you would de setInterval you would be doing nothing [as advised
elswhere] every two seconds, which is an improvement but does not help,
as you want something done, as I presume.

SetTimeout() and set()interval start a seperate process after the stated
amout of miliseconds, they do not "wait" the script for that in their
place.

Furthermore, using document.write() after setup time will destroy the
page INCLUDING the javascript itself.

============================================

Try this code as a seperate HTML file

<div id='myDiv'>Start:<br></div>

<script type='text/javascript'>
var j=0;
myFunction();

function myFunction(){
d = document.getElementById('myDiv');
d.innerHTML+= j++ + "<br>";
if (j<30) setTimeout('myFunction()',500);
};
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #3
JRS: In article <7%*****************@news04.bloor.is.net.cable.rog ers.c
om>, dated Fri, 10 Sep 2004 06:40:03, seen in news:comp.lang.javascript,
QA <QA@alexa.com> posted :
Array.prototype.shuffle= function(times){
var i,j,t,l=this.length;
while(times--){
with(Math){
i=floor(random()*l);j=floor(random()*l);}
t=this[i];this[i]=this[j];this[j]=t;
}
return this;
}


That's not a good way to shuffle; you should read the newsgroup FAQ, and
<URL: http://www.merlyn.demon.co.uk/js-randm.htm>.

Also, l is a poor choice of identifier, at least in News; it cal look
too much like 1.

--
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.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Lars Netzel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.