facebook

Problem with setinterval() only working once: CLOSED

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #342548 Reply

    davidg
    Member

    Hello,

    I am using the javascript setinterval to try and make something appear and then disappear after 3 seconds. When the showdiag() function is executed it works great the first time, but the next times the setinterval() lasts about 1 second or less. Not sure why this is happening.

    
    function showDiag(){
    
    phoneui.showActivityDialog("Page Is Loading");
    setInterval(function(){phoneui.hideActivityDialog()}, 3000)
    
     }

    I have tried several variations including setinterval(Hide, 3000) Where Hide() was another function and it has the same effect as the previous example.

    I want it wait 3 seconds each time, not just the first time it is executed.

    Thanks

    #342549 Reply

    support-michael
    Keymaster

    http://www.w3schools.com/js/js_timing.asp

    Replace setInterval() with setTimeout(). Use setInterval() to run once.

    setTimeout() runs continuously every 3 seconds until your app stops. So everytime you call that function you start yet another timer.

    #342550 Reply

    davidg
    Member

    @support-wayne wrote:

    http://www.w3schools.com/js/js_timing.asp

    Replace setInterval() with setTimeout(). Use setInterval() to run once.

    setTimeout() runs continuously every 3 seconds until your app stops. So everytime you call that function you start yet another timer.

    Thanks that works perfect now. 🙂

    I don’t know why I coudn’t figure that out. :/

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Problem with setinterval() only working once: CLOSED

You must be logged in to post in the forum log in