0

is it possible to Stop Auto refresh when Focused in input box

<input type="text" id="input_box" />

   <script>
var  StopRefresh;

    $('#input_box').focus(function(){
      clearInterval('input_box');
    });

    </script>

this is what i have so far but it does not work can some how achieve this with jquery

james2569
  • 53
  • 4
  • 1
    Possible duplicate of [stop auto refresh when clicked on a div](http://stackoverflow.com/questions/37106862/stop-auto-refresh-when-clicked-on-a-div) – Dan May 09 '16 at 04:51
  • show your auto refresh code also!! – Jack jdeoel May 09 '16 at 04:51
  • clearing All Time out on pages – james2569 May 09 '16 at 04:52
  • The only way to clear an existing interval is to call `clearInterval()` with the id of the one you want to clear. So if you want to clear *all* intervals you need to keep track of the interval ids - perhaps `.push()` them to an array each time you call `setInterval()`, and then in your `.click()` handler loop through the array to call `clearInterval()` for each. – nnnnnn May 09 '16 at 04:53
  • Define a function which call `clearInterval()` function for all the intervals. That's the only way or you can [check this link](http://stackoverflow.com/questions/8635502/how-do-i-clear-all-intervals) – Shubham May 09 '16 at 04:54
  • what if the id i want to click is in another page but no interval is set will i still be able to pull this off with just using `clearInterval('');` – james2569 May 09 '16 at 04:55
  • I kinda changed my question can you guys have alook – james2569 May 09 '16 at 04:59
  • Passing an empty string to `clearInterval()` doesn't do anything. As I already mentioned, you have to pass the id that was previously returned by `setInterval()`. Please read [some documentation](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval). – nnnnnn May 09 '16 at 06:12

1 Answers1

0

store your setIntervel to a variable like

var handle = setInterval('ANYTHING_YOUWANT', 20);

and when you want to clear it use

clearInterval(handle);

if you want to clear on textbox focus so use

<script>
    $(document).ready(function(){
        $('#input_box').focus(function(){
          clearInterval('handle');
        });
    });
</script>
Gomzy
  • 431
  • 4
  • 14