Hi experts,
I have a single line of text field called new_timer and I have applied the following script to my form to start a stopwatch on the timer.
//Initialize time attributes var seconds = 0, minutes = 0, hours = 0,t; function add() { seconds++; if (seconds >= 60) { seconds = 0; minutes++; if (minutes >= 60) { minutes = 0; hours++; } } //creating time value in hh:mm:ss formate var tmp = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds); Xrm.Page.getAttribute("new_timer").setValue(tmp); //recursively calling timer timer(); } //main timer method function timer() { t = setTimeout(add, 1000); } function pause() { clearTimeout(t); } function resume() { timer(); }
I have 2 buttons for pause and resume which I created on ribbon workbench and called pause and resume function, respectively. When I click pause, my timer pauses. When I click resume for the first time, my timer resets to 00:00:00. After that whenever I pause it resume, the timer stops and starts from where I left off.
Why is it resetting for the first time? Is there some error in my Script?
Thanks,
Jon
*This post is locked for comments