Search code examples
javascripthtmlcssmarkup

Force a leading zero to show on page for input type="text" for time format hh:mm:ss


HTML markup <input type="text" value="00:00:00" class="datepicker-time" aria-invalid="false"> does not display the leading zero in a text input with time format hh:mm:ss. Even though the value for the input is 00:00:00, the page shows 0:00:00. How can I force the leading zero to display?


Solution

  • As @Paulie_D said - use type='time' instead of text..

    <input type="time" value="00:00" class="datepicker-time" aria-invalid="false"/>

    One thing to note is that developer.mozilla.org has a lot of good info on how you can use this, both in JS and the general HTML items.