Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input = time, How to allow input of only the hour. No minutes or seconds

I want to allow the user to input a time but only allow the input of hours, no minutes or seconds. I understand a text or number field would be better but need to post the input as a time.

I have tried setting the step attribute to 600, however that removes the milliseconds only.

like image 302
Muhammad Vairnd Avatar asked Sep 23 '19 13:09

Muhammad Vairnd


1 Answers

The step attribute is the step amount you can do in milliseconds, so in this case you should use 60 * 60 * 1000 (60 minutes * 60 seconds * 1000 milliseconds = 1 hour) as the value:

<input type="time" step="3600000" />

Note that this does not work in Safari, but I did test it in Chrome. Safari simply doesnt support this type at all, so no validation happens as far as I can see. Which makes this not universally compatible.

like image 193
somethinghere Avatar answered Oct 09 '22 08:10

somethinghere