0

i have this code its make a count down timer in every refresh for page

i need to add cookie take the time and after finish submit form and start time agine

how can i add the code for cookie

var time = $('#time').val();
document.getElementById('timer').innerHTML = time + ":" + 00;
startTimer();

function startTimer() {
    var presentTime = document.getElementById('timer').innerHTML;
    var timeArray = presentTime.split(/[:]+/);
    var m = timeArray[0];
    var s = checkSecond((timeArray[1] - 1));
    if (s == 59) { m = m - 1 }

    if (m == 0 && s == 0) {
        $('#saveQuestion').submit();
    }

    document.getElementById('timer').innerHTML =
        m + ":" + s;

    setTimeout(startTimer, 1000);
}

function checkSecond(sec) {
    if (sec < 10 && sec >= 0) { sec = "0" + sec };
    if (sec < 0) { sec = "59" };
    return sec;
}
Roman
  • 4,922
  • 3
  • 22
  • 31
  • 1
    Can you explain your problem by adding some more context ? – Partha Roy Oct 27 '17 at 13:31
  • could you add your html? – Roman Oct 27 '17 at 13:49
  • @Roman why its just span to appear a time – Marwan Mohamed Oct 27 '17 at 15:34
  • You're going to find your job is a lot easier if you simply use numeric values for times, like those returned by `Date#getTime()` and `Date.now()`. Calculations are on strictly numeric values, which you can also store in cookies (or wherever), and then you can use those numeric values to render formatted dates into the HTML. Setting cookies via JS is a well-known problem with example code all over, e.g. https://stackoverflow.com/questions/14573223/set-cookie-and-get-cookie-with-javascript – Palpatim Oct 27 '17 at 15:41
  • Possible duplicate of [How do I create and read a value from cookie?](https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie) – Palpatim Oct 27 '17 at 15:42

0 Answers0