Reputation: 181
I am using the input type "time" for selecting a time. When pressing the "delete" or "backspace" button the hour or minutes are set to "--". I want to override this value. When pressing "delete" or "backspace" the default value should be "00". How can i do that?
I am using Google Chrome Version 74.0.3729.131.
<input type="time" name="example">
Upvotes: 0
Views: 575
Reputation: 1215
Have you tried using an event listener, like this?
var input = document.querySelector('input');
input.addEventListener('change', e => {
if (input.value === '') {
input.value = '00:00';
}
});
<input type="time" name="example">
Upvotes: 1