Why it does not give me timeout?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • QA

    #1

    Why it does not give me timeout?

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


    st.shuffle(200) ;

    function donothing () {return true;}

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

    setTimeout('don othing()', 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.


  • oeyvind toft

    #2
    Re: Why it does not give me timeout?

    "QA" <QA@alexa.com > skrev i melding
    news:7%b0d.3453 $k14.1086@news0 4.bloor.is.net. cable.rogers.co m...[color=blue]
    > I want to display them every 2 second. After everything is displayed it[/color]
    then[color=blue]
    > stops.
    > But it does not give me the 2s delay. It displays everything once.
    >
    >[/color]

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

    Oeyvind





    Comment

    • Evertjan.

      #3
      Re: Why it does not give me timeout?

      QA wrote on 10 sep 2004 in comp.lang.javas cript:[color=blue]
      >
      > function donothing () {return true;}
      >
      > for(j=0;j<st.le ngth;j++){
      >
      > setTimeout('don othing()', 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.[/color]

      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'>Star t:<br></div>

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

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

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • Dr John Stockton

        #4
        Re: Why it does not give me timeout?

        JRS: In article <7%b0d.3453$k14 .1086@news04.bl oor.is.net.cabl e.rogers.c
        om>, dated Fri, 10 Sep 2004 06:40:03, seen in news:comp.lang. javascript,
        QA <QA@alexa.com > posted :
        [color=blue]
        >Array.prototyp e.shuffle= function(times) {
        >var i,j,t,l=this.le ngth;
        >while(times--){
        >with(Math){
        >i=floor(random ()*l);j=floor(r andom()*l);}
        >t=this[i];this[i]=this[j];this[j]=t;
        >}
        >return this;
        >}[/color]

        That's not a good way to shuffle; you should read the newsgroup FAQ, and
        <URL: http://www.merlyn.demo n.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        Working...