Simple Way to create Timer using Javascript
Following is the main logic to display dynamic timer using javascript.
Main Logic in Javascript:
function display() { if (seconds > 60) { minutessplit = seconds / 60; minutes = [(minutessplit > 0) ? Math.floor(minutessplit) : Math.ceil(minutessplit)]; seconds = (minutes * 60) - seconds; } gettime(); } function gettime() { if (milisec <= 0) { milisec = 9; seconds -= 1; } if (seconds <= -1) { seconds = 60; milisec = 0; minutes -= 1; } if (minutes <= -1) { seconds = 0; minutes += 1; } else milisec -= 1 document.getElementById('d2').value = minutes + ":" + seconds + " : " + milisec; if (minutes == 0 && seconds == 0 && milisec == 0) { alert("Time Out"); } else { setTimeout("gettime()", 100) } }Design part in Html
- Timer : 10-Secs
- Timer : 30-Secs
- Timer : 1-Min
- Timer : 2-Mins
- Timer : 3-Mins
Labels: .Net Tutorials, Ajax, C#, javascript
<< Home