html - Javascript countdown timer with 05 instead of 5 seconds? -


i have created 1 in javascript! timer counting down time 14:59 00:00 minutes. need prevent seconds going 1 digit.

for example:
14:05 - allowed , needed achieve
14:5 - not allowed , need rid of situation.

<html> <head>     <script type="text/javascript">         var interval;         var minutes = 14;         var seconds = 05;         window.onload = function () {             countdown('atskaite');         }          function countdown(element) {             interval = setinterval(function () {                 var el = document.getelementbyid(element);                 if (seconds == 0) {                     if (minutes == 0) {                         clearinterval(interval);                         return;                     } else {                         minutes--;                         seconds = 60;                     }                 }                 el.innerhtml = minutes + ':' + seconds;                 seconds--;             }, 1000);         }     </script> </head>  <body>     <div id="atskaite"></div> </body> </html> 


any help, please?

simply add check before assign el.innerhtml, so:

if (seconds < 10) seconds = '0' + seconds; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -