Results 1 to 3 of 3

Thread: javascripts conflict? some help required please

  1. #1
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascripts conflict? some help required please

    Hi,
    could anyone tell me why the lottery picker in the link below doesn't always work (does not stop the count), sometimes it does and sometimes it doesn't. In Firefox or IE

    http://tstiger.org.uk/stuff.htm

    I thought it might be var conflicts as there are some but i changed each in turn to no avail.

    FYI, I am not a coder just a tinkerer, I can do html a bit and the website was done to help out and keep costs low, but I would like to keep the java on it if poss

    ps yes i know the slider game works only in IE but the cadets like it and they all use IE

    Thanks in advance

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I would guess, especially if it is only a problem sometimes, that it has to do with the nature of timeouts. If one timeout is cancelling another timeout that is constantly being reissued, they would both have to fire at the right moments for this to work out in all cases.

    A better strategy would be to have one be an interval. An interval is only issued once so, the precise timing of its cancellation wouldn't be so critical. I would remove this from the script:

    Code:
      T=setTimeout('lotto()',20);
    add the variable T formally to the global scope but, use something a bit more unique, say Tlottovar. To do this, near the top of the script have:

    Code:
    /*****************************************
    * Lottery Picker (By Kurt at kurt.grigg@virgin.net)
    * Featured on/available at http://www.dynamicdrive.com/
    * Modified by DynamicDrive.com for below config options
    * This notice must stay intact for use.
    *****************************************/
    
    var totalnumbers=6 //input total numbers to generate
    var lowerbound=1   //input lower bound for each random number
    var upperbound=49  //input upper bound for each random number
    var Tlottovar;
    
    function lotto(){
     . . .
    Now, when you call lotto() from your button, it can look like so:

    Code:
    <input type="button" value="Lottery Number Picker" onclick="Tlottovar=setInterval('lotto()', 20);StOp();">
    and your StOp() function would clear it like so:

    Code:
    function StOp(){
    setTimeout('clearInterval(Tlottovar)',1400);
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John,
    Many thanks for that my friend
    success,

    I will now try to figure out why it works so I can do it myself another time

    PdS

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •