Jquery SetInterval help

  • steve101
  • Beginner
  • Beginner
  • steve101
  • Posts: 35

Post 3+ Months Ago

Hi,

I have a problem with setInterval (jquery). It works great, but I wan't the element to stop refreshing when a textarea is selected (so that users can insert text).

Here is the refresh code I'm using currently.

JAVASCRIPT Code: [ Select ]
 $(document).ready(function() {
   $("#container").load("php/functions.php?page=wall");
 
   refreshId = setInterval(function() {
      $("#container").load("php/functions.php?page=wall&r="+Math.random());
 
   
   }, 1000);
});
 
  1.  $(document).ready(function() {
  2.    $("#container").load("php/functions.php?page=wall");
  3.  
  4.    refreshId = setInterval(function() {
  5.       $("#container").load("php/functions.php?page=wall&r="+Math.random());
  6.  
  7.    
  8.    }, 1000);
  9. });
  10.  

How could I alter this, for example, to make the interval stop whilst the the text area is in focus/being typed in?

Many Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Declare "refreshId" as a global variable outside of the function so that future events can access it. Then attach a focus event handler to the container.

Code: [ Select ]
$('#container').focus(function(){
  clearInterval(refreshId);
});
  1. $('#container').focus(function(){
  2.   clearInterval(refreshId);
  3. });

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.