Link to home
Start Free TrialLog in
Avatar of Mulith
Mulith

asked on

Button to stop and reset countdown?

Hi All,

Another developer on EE helped me partially with a piece of code i'd like to implement.

I was looking for a hidden div that once triggered started a count down until the users sessions expired.

The script that sort of helped is here http://jsfiddle.net/Proculopsis/FXZxQ/129/

What I really want this hidden div to do is appear when the users session has 60 seconds left. It also needs a button to extend the session and one to end the session immediately.

Could anybody help me achieve this result? For testing purposes session length can be 2 minutes.
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

I'll look later in detail but it will look like


var tId;

$("button").click(function() {
    $("#session-warning").toggle();
    tId=setInterval(decrement, 1000);
});

function decrement() {
    var timeLeft = $("#time-left");
    var seconds = Number(timeLeft.text()) - 1;
    timeLeft.text(seconds)
    if (seconds == 60) $("#session-warning").toggle();
    if (seconds<=0){
        $("#session-warning").text("Logout");
        clearInterval(tId);
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial