5

Scenario is that I have written a function for auto refresh on form element and I want onclick event on login button to disable the auto refresh function.

I'm not able to get disable the autorefresh and the page still refreshes.

My code is:

$('#form').ready(function () { //Increment the idle time counter every minute.
    var idleInterval = setInterval("timerIncrement()", 15000); // 1 minute

    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e){
        idleTime = 0;
    });
});

function timerIncrement() {
    idleTime = idleTime + 1;
    if (idleTime > 2) { // 20 minutes
        window.location.reload();
    }
}

$('#login').ready(function () {

    alert("working promptly");
    //Zero the idle timer on mouse movement.
    $(this).click(function (e) {
        alert("Hi In click !");
        $('#form').attr("disabled","true"); 
    });


});
falsarella
  • 12,217
  • 9
  • 69
  • 115
anu
  • 59
  • 1
  • 2
  • 4
  • 1
    `setInterval("timerIncrement()", 15000);` should be `setInterval("timerIncrement", 15000);` and omg, how many errors can you make in a script? – Val Jan 17 '12 at 10:35
  • 2
    Actually, it should be `setInterval(timerIncrement, 15000);` - eval is evil! – Jonas Høgh Jan 17 '12 at 10:39
  • @anu this is a very common problem, use `prop` instead of `attr` and it will work. – noob Jan 17 '12 at 11:42

1 Answers1

1

I guess you are needing to clear the interval timer:

$(this).click(function (e) {
    alert("Hi In click !");
    $('#form').attr("disabled","true"); 
    clearInterval(idleInterval);
});
falsarella
  • 12,217
  • 9
  • 69
  • 115