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


Groups > comp.lang.javascript > #16325 > unrolled thread

setimeout() problem

Started by"jmrw" <jmrw@free.fr>
First post2012-10-03 07:27 +0200
Last post2012-10-04 12:26 +0200
Articles 20 — 7 participants

Back to article view | Back to comp.lang.javascript


Contents

  setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 07:27 +0200
    Re: setimeout() problem ankit pandey <blackhill08@gmail.com> - 2012-10-02 22:49 -0700
      Re: setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 07:57 +0200
        Re: setimeout() problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-03 06:24 +0000
          Re: setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 09:55 +0200
            Re: setimeout() problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-03 10:56 +0000
    Re: setimeout() problem Tim Streater <timstreater@greenbee.net> - 2012-10-03 09:17 +0100
      Re: setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 10:37 +0200
      Re: setimeout() problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-03 10:59 +0000
    Re: setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 12:04 +0200
      Re: setimeout() problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-03 11:02 +0000
        Re: setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 16:52 +0200
          Re: setimeout() problem "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-03 15:05 +0000
          Re: setimeout() problem Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-04 20:00 +0100
      Re: setimeout() problem Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-03 05:54 -0700
        Re: setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 16:50 +0200
          Re: setimeout() problem Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-03 10:10 -0700
    Re: setimeout() problem "jmrw" <jmrw@free.fr> - 2012-10-03 22:15 +0200
      Re: setimeout() problem Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-03 13:30 -0700
      Re: setimeout() problem Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-10-04 12:26 +0200

#16325 — setimeout() problem

From"jmrw" <jmrw@free.fr>
Date2012-10-03 07:27 +0200
Subjectsetimeout() problem
Message-ID<506bccbe$0$16500$426a74cc@news.free.fr>
http://www.jmrw.com/Chess/Tableau_echecs/index.htm#diaporama

On this page the button "stop" doesn't work everytime..

<button id="but_stop" onClick="stop()"> stop </button>

function stop() {clearTimeout(play); play = false; }

It should stop this function:

function diaporamarandom() {
c++;
document.getElementById('quantite').value = c;
c=Math.floor(Math.random()*listechrono.length)
document.getElementById('vue').style.backgroundImage = 
'url(images/'+liste[c]+'.jpg)';
play = setTimeout('diaporamarandom()',tempo); }

I don't understand why.

thanks

jmrw 

[toc] | [next] | [standalone]


#16326

Fromankit pandey <blackhill08@gmail.com>
Date2012-10-02 22:49 -0700
Message-ID<08869374-503e-41a0-aee6-69fb271bf5d7@googlegroups.com>
In reply to#16325
On Wednesday, 3 October 2012 10:57:26 UTC+5:30, jmrw  wrote:
> http://www.jmrw.com/Chess/Tableau_echecs/index.htm#diaporama
> 
> 
> 
> On this page the button "stop" doesn't work everytime..
> 
> 
> 
> <button id="but_stop" onClick="stop()"> stop </button>
> 
> 
> 
> function stop() {clearTimeout(play); play = false; }
> 
> 
> 
> It should stop this function:
> 
> 
> 
> function diaporamarandom() {
> 
> c++;
> 
> document.getElementById('quantite').value = c;
> 
> c=Math.floor(Math.random()*listechrono.length)
> 
> document.getElementById('vue').style.backgroundImage = 
> 
> 'url(images/'+liste[c]+'.jpg)';
> 
> play = setTimeout('diaporamarandom()',tempo); }
> 
> 
> 
> I don't understand why.
> 
> 
> 
> thanks
> 
> 
> 
> jmrw

It works on 3rd time click

[toc] | [prev] | [next] | [standalone]


#16327

From"jmrw" <jmrw@free.fr>
Date2012-10-03 07:57 +0200
Message-ID<506bd3c2$0$2351$426a74cc@news.free.fr>
In reply to#16326
> It works on 3rd time click

Why not on the first time click?

jmrw 

[toc] | [prev] | [next] | [standalone]


#16328

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-10-03 06:24 +0000
Message-ID<XnsA0E1557A0979Aeejj99@194.109.133.133>
In reply to#16327
jmrw wrote on 03 okt 2012 in comp.lang.javascript:

>> It works on 3rd time click
> 
> Why not on the first time click?

Declare play globally.

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

var play = true;

function stop() {
   // clearTimeout(play); // not needed now
   play = false; 
};

function diaporamarandom() {
   if (!play) return;
   ...........

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

[toc] | [prev] | [next] | [standalone]


#16330

From"jmrw" <jmrw@free.fr>
Date2012-10-03 09:55 +0200
Message-ID<506bef7b$0$6112$426a74cc@news.free.fr>
In reply to#16328
Thanks

My var play is defined globally line 663 I think

Line 674 I added :

------------------
function diaporamarandom() {
 if (!play) return;
-----------------

diaporamrandom() does'nt work anymore.

if  I put

-----------------
function diaporamarandom() {
play=true;
 if (!play) return;
-----------------

diaporamarandom() works, but stop() does'nt anymore.

jmrw




"Evertjan." <exxjxw.hannivoort@inter.nl.net> a écrit dans le message de 
news: XnsA0E1557A0979Aeejj99@194.109.133.133...
> jmrw wrote on 03 okt 2012 in comp.lang.javascript:
>
>>> It works on 3rd time click
>>
>> Why not on the first time click?
>
> Declare play globally.
>
> =============
>
> var play = true;
>
> function stop() {
>   // clearTimeout(play); // not needed now
>   play = false;
> };
>
> function diaporamarandom() {
>   if (!play) return;
>   ...........
>
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress) 

[toc] | [prev] | [next] | [standalone]


#16336

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-10-03 10:56 +0000
Message-ID<XnsA0E183B62D8Eeejj99@194.109.133.133>
In reply to#16330
jmrw wrote on 03 okt 2012 in comp.lang.javascript:

> My var play is defined globally line 663 I think

Use:

var play =  true;


> 
> Line 674 I added :
> 
> ------------------
> function diaporamarandom() {
>  if (!play) return;
> -----------------
> 
> diaporamrandom() does'nt work anymore.

Ofcourse it "works", it just returns if play is false.

> 
> if  I put
> 
> -----------------
> function diaporamarandom() {
> play=true;

Put that as the global definition outside the function.

>  if (!play) return;
> -----------------
> 
> diaporamarandom() works, but stop() does'nt anymore.

Are you just experimenting with random code, 
or are you programming while understanding the code you write down?

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

[toc] | [prev] | [next] | [standalone]


#16331

FromTim Streater <timstreater@greenbee.net>
Date2012-10-03 09:17 +0100
Message-ID<timstreater-168B24.09172403102012@news.individual.net>
In reply to#16325
In article <506bccbe$0$16500$426a74cc@news.free.fr>,
 "jmrw" <jmrw@free.fr> wrote:

> http://www.jmrw.com/Chess/Tableau_echecs/index.htm#diaporama
> 
> On this page the button "stop" doesn't work everytime..
> 
> <button id="but_stop" onClick="stop()"> stop </button>

<button type="button" id="but_stop" etc etc

Otherwise the button will submit the page every time you click it.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#16332

From"jmrw" <jmrw@free.fr>
Date2012-10-03 10:37 +0200
Message-ID<506bf93b$0$16473$426a74cc@news.free.fr>
In reply to#16331
adding type="button" in
  <button id="but_stop" onClick="stop()"> stop </button>
changes nothing

jmrw


"Tim Streater" <timstreater@greenbee.net> a écrit dans le message de news: 
timstreater-168B24.09172403102012@news.individual.net...
> In article <506bccbe$0$16500$426a74cc@news.free.fr>,
> "jmrw" <jmrw@free.fr> wrote:
>
>> http://www.jmrw.com/Chess/Tableau_echecs/index.htm#diaporama
>>
>> On this page the button "stop" doesn't work everytime..
>>
>> <button id="but_stop" onClick="stop()"> stop </button>
>
> <button type="button" id="but_stop" etc etc
>
> Otherwise the button will submit the page every time you click it.
>
> -- 
> Tim
>
> "That excessive bail ought not to be required, nor excessive fines 
> imposed,
> nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689 

[toc] | [prev] | [next] | [standalone]


#16337

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-10-03 10:59 +0000
Message-ID<XnsA0E1841BCA2A0eejj99@194.109.133.133>
In reply to#16331
Tim Streater wrote on 03 okt 2012 in comp.lang.javascript:

> In article <506bccbe$0$16500$426a74cc@news.free.fr>,
>  "jmrw" <jmrw@free.fr> wrote:
> 
>> http://www.jmrw.com/Chess/Tableau_echecs/index.htm#diaporama
>> 
>> On this page the button "stop" doesn't work everytime..
>> 
>> <button id="but_stop" onClick="stop()"> stop </button>
> 
> <button type="button" id="but_stop" etc etc
> 
> Otherwise the button will submit the page every time you click it.

Only if the code is inside a <form>,
and even then only on certain inferior browsers.


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

[toc] | [prev] | [next] | [standalone]


#16334

From"jmrw" <jmrw@free.fr>
Date2012-10-03 12:04 +0200
Message-ID<506c0da6$0$1709$426a74cc@news.free.fr>
In reply to#16325
Nobody can help me?

jmrw 

[toc] | [prev] | [next] | [standalone]


#16338

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-10-03 11:02 +0000
Message-ID<XnsA0E184BD3B972eejj99@194.109.133.133>
In reply to#16334
jmrw wrote on 03 okt 2012 in comp.lang.javascript:

> Nobody can help me?

Strange question,
even ideomatically questionable, 
only valid true if you do not wish to be helped,
define 'can' as 'will'
and define 'help' as 'take over your job or quest'.

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

[toc] | [prev] | [next] | [standalone]


#16344

From"jmrw" <jmrw@free.fr>
Date2012-10-03 16:52 +0200
Message-ID<506c510f$0$2355$426a74cc@news.free.fr>
In reply to#16338
Sorry, I am a beginner in javascript.and my language is french, so it is a 
bit difficult for me.

I have been told to put var play=true; as a global variable. I think I have 
done it and the problem is not solved.

Thanks

jmrw

"Evertjan." <exxjxw.hannivoort@inter.nl.net> a écrit dans le message de 
news: XnsA0E184BD3B972eejj99@194.109.133.133...
> jmrw wrote on 03 okt 2012 in comp.lang.javascript:
>
>> Nobody can help me?
>
> Strange question,
> even ideomatically questionable,
> only valid true if you do not wish to be helped,
> define 'can' as 'will'
> and define 'help' as 'take over your job or quest'.
>
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress) 

[toc] | [prev] | [next] | [standalone]


#16345

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2012-10-03 15:05 +0000
Message-ID<XnsA0E1ADF1B2AA0eejj99@194.109.133.133>
In reply to#16344
jmrw wrote on 03 okt 2012 in comp.lang.javascript:
> "Evertjan." <exxjxw.hannivoort@inter.nl.net> a écrit dans le message
> de news: XnsA0E184BD3B972eejj99@194.109.133.133...
>> jmrw wrote on 03 okt 2012 in comp.lang.javascript:
>>
>>> Nobody can help me?
>>
>> Strange question,
>> even ideomatically questionable,
>> only valid true if you do not wish to be helped,
>> define 'can' as 'will'
>> and define 'help' as 'take over your job or quest'.

[Please do not toppost, and do not quote singatures., coorected]

> Sorry, I am a beginner in javascript.and my language is french, so it
> is a bit difficult for me.

Our language is Javascript. ;-)
This is not an English only NG, some of us are French natives [not me].
 
> I have been told to put var play=true; as a global variable. I think I
> have done it and the problem is not solved.

Getting help is not the same as having your problem solved.

Please make a minimalistic code where you show what the problem is,
and show it to us.

Try to understand what each statement does and why.
Perhaps add temporary breakpoints to undestand the changing of the value of 
"play". Or use the console provided in some browsers.

If you understand the your problem yourself, perhaps you can fix it, 
otherwise maybe someone here will point you to the error in the code or in 
the expectation.

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

[toc] | [prev] | [next] | [standalone]


#16403

FromDr J R Stockton <reply1240@merlyn.demon.co.uk.invalid>
Date2012-10-04 20:00 +0100
Message-ID<+UaX9hQjzdbQFwUD@invalid.uk.co.demon.merlyn.invalid>
In reply to#16344
In comp.lang.javascript message <506c510f$0$2355$426a74cc@news.free.fr>,
Wed, 3 Oct 2012 16:52:07, jmrw <jmrw@free.fr> posted:

>Sorry, I am a beginner in javascript.and my language is french, so it is a
>bit difficult for me.

Then post in French.  The educated here will generally it easier to
understand good plain French than to understand what is thought to by a
French person to be sufficiently like English.

If you want the others to be able to read it, then add an English
version; but put at the top "posted in both French and English".

Then you can cross-post your question to c.l.j & fr.c.l.j rather than
posting multiply.

It's also a good idea to say that you have read the FAQ of this
newsgroup (if true).

-- 
 (c) John Stockton, nr London UK               Reply address via Home Page.
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

[toc] | [prev] | [next] | [standalone]


#16340

FromScott Sauyet <scott.sauyet@gmail.com>
Date2012-10-03 05:54 -0700
Message-ID<e09bcae9-32f4-41bf-a75a-2bad8dac682b@a17g2000yqg.googlegroups.com>
In reply to#16334
jmrw wrote:
> Nobody can help me?

Probably not.

You post a problem without bothering to format your source code for
readability, to give enough context to understand it.  Your URL points
to a page that doesn't validate, with source code that's very
difficult to read, and seems to be a mix of custom code and very old
auto-generated code.

Only four and a half hours later, after three separate people have
offered what help they can, you respond with this plaintive moan.  No
probably no one can help you.

It's a shame, because the page looks interesting, and I'd like to
offer help.

  -- Scott

[toc] | [prev] | [next] | [standalone]


#16342

From"jmrw" <jmrw@free.fr>
Date2012-10-03 16:50 +0200
Message-ID<506c50a5$0$16496$426a74cc@news.free.fr>
In reply to#16340
Sorry, I am a beginner in javascript.

I whish and improve.

I have been told to put var play=true; as a global variable. I think I have 
done it and the problem is not solved.

Thanks

jmrw


"Scott Sauyet" <scott.sauyet@gmail.com> a écrit dans le message de news: 
e09bcae9-32f4-41bf-a75a-2bad8dac682b@a17g2000yqg.googlegroups.com...
> jmrw wrote:
>> Nobody can help me?
>
> Probably not.
>
> You post a problem without bothering to format your source code for
> readability, to give enough context to understand it.  Your URL points
> to a page that doesn't validate, with source code that's very
> difficult to read, and seems to be a mix of custom code and very old
> auto-generated code.
>
> Only four and a half hours later, after three separate people have
> offered what help they can, you respond with this plaintive moan.  No
> probably no one can help you.
>
> It's a shame, because the page looks interesting, and I'd like to
> offer help.
>
>  -- Scott 

[toc] | [prev] | [next] | [standalone]


#16349

FromScott Sauyet <scott.sauyet@gmail.com>
Date2012-10-03 10:10 -0700
Message-ID<760d6d77-b699-4c35-b5b1-c35352bb0bf2@a7g2000yqo.googlegroups.com>
In reply to#16342
jmrw wrote:
> Sorry, I am a beginner in javascript.

There's nothing wrong with that.  Beginners are welcome here.  But you
need to be willing to learn and abide by the conventions of this
group.  Here's some starter information:

    <http://jibbering.com/faq/#posting>

> I have been told to put var play=true; as a global variable. I think I have
> done it and the problem is not solved.

I think Evertjan's advice is what you really need.  Try to make a
smaller test case that demonstrates the problem but doesn't have as
much clutter as your main code.  If you don't find the issue yourself
in doing this, you will be much more likely to get people here willing
to help.

Best of luck,

  -- Scott

[toc] | [prev] | [next] | [standalone]


#16356

From"jmrw" <jmrw@free.fr>
Date2012-10-03 22:15 +0200
Message-ID<506c9cf3$0$21929$426a74cc@news.free.fr>
In reply to#16325
I apologize.

Cleaning and formating my code I found the error (an unnecessary function 
which disturbed)

I understand now what you were explaining me about formating  source code 
for readability.

I understand too that I cannot expect others do the bad job and the kind of 
questions I can ask in this newsgroup

Thanks having severe with me. It helped me.

My only excuse is I am a beginner.

jmrw 

[toc] | [prev] | [next] | [standalone]


#16357

FromScott Sauyet <scott.sauyet@gmail.com>
Date2012-10-03 13:30 -0700
Message-ID<f05c86b6-ce23-4c5c-b5c1-deaefddb13cf@z8g2000yql.googlegroups.com>
In reply to#16356
jmrw wrote:
> Cleaning and formating my code I found the error (an unnecessary function
> which disturbed)

I'm very glad to hear it.  Do you understand how and why it
interfered?


> I understand now what you were explaining me about formating  source code
> for readability.

I was discussing it for the purposes of posting here, but it's a
useful habit in general.  If you can understand the structure at a
glance, you can spend more of your time trying to understand the
logic.


> I understand too that I cannot expect others do the bad job and the kind of
> questions I can ask in this newsgroup

There are plenty of questions you are welcome to ask here.  The main
thing is that you need to be willing to do enough on your own to make
it interesting for us to spend time on it.  And please remember that
it is not a paid help group, but a group of volunteers who are here
for discussing interesting aspects of the language, including at times
helping beginners.


> Thanks having severe with me. It helped me.

You're welcome, I guess.  It's funny, because I imagine my reputation
here is not one of being particularly harsh.  We have plenty of harsh
voices.  But your "Nobody can help me?" really annoyed me for some
reason.  I'm not usually so harsh.  I'm glad it helped.


> My only excuse is I am a beginner.

It's a reasonable excuse.  We expect you continue being a beginner for
a while.  But please do take away some lessons in appropriate posting
to USENET.

Cheers,

  -- Scott

[toc] | [prev] | [next] | [standalone]


#16387

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2012-10-04 12:26 +0200
Message-ID<506d6439$0$6934$e4fe514c@news2.news.xs4all.nl>
In reply to#16356
On 10/3/2012 10:15 PM, jmrw wrote:
> I apologize.
>
> Cleaning and formating my code I found the error (an unnecessary function
> which disturbed)
>
> I understand now what you were explaining me about formating  source code
> for readability.
>
> I understand too that I cannot expect others do the bad job and the kind of
> questions I can ask in this newsgroup
>
> Thanks having severe with me. It helped me.
>
> My only excuse is I am a beginner.
>
> jmrw
>
>

My compliments.
Most people wouldn't have bothered to post that.
You have the right attitude.

Regards,
Erwin Moller

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web