Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #32529

Re: setInterval

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From "Julio P. Di Egidio" <julio@diegidio.name>
Newsgroups comp.lang.javascript
Subject Re: setInterval
Date Tue, 7 Feb 2017 06:22:25 +0100
Organization A noiseless patient Spider
Lines 1
Message-ID <o7blfb$vpl$1@dont-email.me> (permalink)
References <6cb902b0-8913-4b65-954d-5d9f0e60ee95@googlegroups.com> <4cbfae02-e217-436d-8c41-004de444915c@googlegroups.com> <e806c910-79e5-4ac2-976f-b07b0b7e0cba@googlegroups.com> <daeac930-8fcd-48c9-b280-75144f751b0e@googlegroups.com> <8e741582-e2a8-4713-b49d-6bd5a50a8317@googlegroups.com> <fb53f70d-b831-4f1e-b290-eaad38124c77@googlegroups.com> <ac8011b3-9496-4559-a42b-c656798bfc44@googlegroups.com> <87h947e7f5.fsf@bsb.me.uk> <82f4ba9f-8d80-4769-842a-5a9b066efb5a@googlegroups.com> <5898e78d$0$18070$e4fe514c@newszilla.xs4all.nl> <3141f801-2946-40fc-87ad-97668f7061e4@googlegroups.com> <XnsA714F29A92D37eejj99@194.109.6.166> <c8d749e4-8813-498c-a763-bc345854732d@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; format=flowed; charset="UTF-8"; reply-type=original
Content-Transfer-Encoding 7bit
Injection-Date Tue, 7 Feb 2017 05:20:44 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="1c2715a88b56e96fd2e61ad2b5361d25"; logging-data="32565"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mqctVnIvOFDmKiJaZoylH+28fK7NsRwk="
X-MimeOLE Produced By Microsoft MimeOLE V16.4.3528.331
In-Reply-To <c8d749e4-8813-498c-a763-bc345854732d@googlegroups.com>
X-Newsreader Microsoft Windows Live Mail 16.4.3528.331
Importance Normal
Cancel-Lock sha1:77D0znWu2p1uihA4dOGKbEioPOg=
X-Priority 3
X-MSMail-Priority Normal
Xref csiph.com comp.lang.javascript:32529

Show key headers only | View raw


wrote in message 
news:c8d749e4-8813-498c-a763-bc345854732d@googlegroups.com...
>
> function INTRO(){
>   mycount=25;
>   document.getElementById('mysubset').selectedIndex=1;
>   while (mycount>-1){
>   refresh = setTimeout("COUNTDOWN();",200);
>   mycount--;
> }
> }
>
> One would think that this would set a timeout 26 times and call the 
> function COUNTDOWN, but that is not what it does.

That is not what one would think...

Here is a working example for your perusal.  Study the language, read e.g. 
Crockford's articles, and read the JS spec while you code, best on MDN in my 
opinion.  Then feel free to ask questions.

----------------------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Countdown sample</title>
</head>
<body>
    <p>Count value: <span id="lblCnt">0</span></p>

    <p><button id="btnRun" onclick="run()">Count down</button></p>

    <script>
        "use strict";

        var lblCnt = document.getElementById("lblCnt");
        var btnRun = document.getElementById("btnRun");

        var StartCount = 10;
        var CountDelay = 125;

        function run()
        {
            btnRun.disabled = true;

            run_loop(StartCount);
        }

        function run_loop(cnt)
        {
            update(cnt);

            if (cnt === 0)
            {
                btnRun.disabled = false;

                return;
            }

            setTimeout(function ()
            {
                run_loop(--cnt);
            }, CountDelay);
        }

        function update(cnt)
        {
            lblCnt.innerText = "" + cnt;
        }
    </script>
</body>
</html>
----------------------------------------------

HTH,

Julio

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

setInterval jonas.thornvall@gmail.com - 2017-02-05 23:26 -0800
  Re: setInterval jonas.thornvall@gmail.com - 2017-02-05 23:30 -0800
    Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:17 -0800
      Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:24 -0800
        Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:36 -0800
          Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 01:10 -0800
            Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 01:20 -0800
              Re: setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-06 14:10 +0000
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 11:25 -0800
                Re: setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-06 21:12 +0000
                Re: setInterval Silvio <silvio@internet.com> - 2017-02-06 22:15 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:17 -0800
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:50 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 20:57 -0800
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 21:15 -0800
                Re: setInterval "Julio P. Di Egidio" <julio@diegidio.name> - 2017-02-07 06:22 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 22:09 -0800
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-06 22:27 -0800
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 22:45 -0800
                Re: setInterval Jake Jarvis <pig_in_shoes@yahoo.com> - 2017-02-07 11:13 +0100
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 17:23 +0100
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 11:54 -0800
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 21:54 +0100
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 13:50 -0800
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 23:19 +0100
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 15:33 -0800
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-09 00:23 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-07 11:33 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:28 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:26 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:24 +0100
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 04:36 +0100
            Re: setInterval Silvio <silvio@internet.com> - 2017-02-06 16:13 +0100
              Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 12:10 -0800
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 12:27 -0800
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:16 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:28 -0800
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:45 +0100
                Re: setInterval Tim Streater <timstreater@greenbee.net> - 2017-02-06 21:25 +0000
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:19 +0100
  Re: setInterval JJ <jj4public@vfemail.net> - 2017-02-06 20:07 +0700
    Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 16:00 +0100
      Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 11:06 -0800
        Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:08 +0100
          Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:26 -0800
            Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:41 +0100

csiph-web