setSelectionRange for input type="time"

1k views Asked by At

I have a dialog box that has an HTML5 input field with a type="time" in it.

When the dialog appears, I want to default the editing to the "minutes" portion of the dialog. I can't see a way to do it.

Here is a jsFiddle example that tries to use:

$("#t")[0].setSelectionRange(3, 5);

to no avail.

Is there a way to do this?


NOTE: the w3c spec here specifically has this quote:

The following IDL attributes and methods do not apply to the element: checked, files, selectionStart, selectionEnd, and selectionDirection IDL attributes; select(), setRangeText(), and setSelectionRange() methods.

Which might mean this simply isn't possible.


NOTE 2: Chrome throws this error when attempting to call this method. Other browsers may throw different errors:

Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.

1

There are 1 answers

0
Endothermic_Dragon On

Just set it using some js.

document.getElementsByTagName("INPUT")[0].value = "13:24"
<input type="time" id="appt" name="appt" min="09:00" max="18:00" required>