1

I have an pop up dialog that appears after every one minute and in that pop up, I have a timer that count it's time starting from 1 minute, till 0. If user presses yes in the popup dialog, the modalpop is again reset to call again after one minute. My problem is that it was working fine until I have not introduced startBackCountDown() which creates a timer inside that modal popup. Can somebody please help me. I am stucked here.

    var mins = 1;
    var secs = 0;
    var timer;


    //240000-Four minutes
    // 120000- two minutes
    //60000-OneMinute
    var myVar = setInterval(function () { myTimer() }, 60000);
    function myTimer() {
        startBackCountDown();
        $("#dialog").dialog("open");

    }



    function startBackCountDown() {
        timer = setInterval('update()', 1000);
    }
    function update() {
        var timeField = document.getElementById('Showtime');
        if (secs == 0) {
            if (mins == 0) {
                timeField.innerHTML = "Time's up!";
                clearInterval(timer);
                //alert("Time's up");
                return;
            }
            mins--;
            secs = 59;
        } else {
            secs--;
        }
        if (secs < 10) {
            timeField.innerHTML = 'Time left: ' + mins + ':0' + secs;
        } else {
            timeField.innerHTML = 'Time left: ' + mins + ':' + secs;
        }
    }


    function ClearTimerValues() {
        window.clearInterval(myVar);
        clearInterval(timer);
    }

    function SetTimerValuesAgain() {
        var client_Name = '@Session["ClientFullName"]';
        var Client_Id = '@Session["Client_LoginID"]';
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "../Account/ResetUser",
            data: "{'User_ID':'" + Client_Id + "','Client_Name':'" + client_Name + "'}",
            dataType: "json",
            success: function (data) {
                if (data.Data == '1') {
                    myVar = setInterval(function () { myTimer() }, 60000);
                    //window.clearInterval(timer);
                    mins = 1;
                    secs = 0;
                }
                else {
                    window.clearInterval(myVar);
                    window.location = "/Account/login";
                }
            },
            error: function (xhr) {
            }
        });
    }



    $(function () {
        $("#dialog").dialog({
            resizable: false,
            height: 140,
            modal: true,
            autoOpen: false,
            show: "blind",
            hide: "blind",
            buttons: {
                "Yes": function () {
                    SetTimerValuesAgain();
                    $(this).dialog("close");
                },
                "No": function () {
                    ClearTimerValues();
                    $(this).dialog("close");
                }
            }
        });
    });
2
  • 1
    timer = setInterval('update()', 1000); should be written as timer = setInterval(function(){ update() }, 1000);
    – rt2800
    Commented Feb 28, 2014 at 13:13
  • I also find problem while creating timer. Please provide a simple better example
    – Prince
    Commented Feb 28, 2014 at 15:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.