1
I need to make a onKeyUp
in input Date
so that the user cannot choose a date later than the field cut-off date.
Type:
<input type='date' id='data' name='data' max="<?php echo date('Y-m-d'); ?>" required />
Won’t do any good onkey down
. It needs to be during the typing of the field and not in the choice in the combo.
Does it have to block typing in the text box with Html5?
But then the user can withdraw...
It’s hard.
Everything done on the front end can be changed. The important thing is to validate the information on the server.
– Sam
ok, but even if changed, is there a way to deny the user who decides to type in the combo instead of choosing the date in the combo to choose a posthumous date? It may be inertial to validate the date with jQuey/Javascript and clear the date if it is higher
– Carlos Rocha
I never let the user type. I always put the option to choose the date through a Datepicker.
– Diego Souza
I had put an answer with
onkeydown='event.preventDefault();'
, but since you said it didn’t fit, I removed the answer.– Sam
Remember that even if the user type a value out of proper the input becomes invalid. Invalidation of the field works, only it only prevents the form from being sent and not the date being prevented from being typed. Anyway, without validation on the server, it is useless to validate on the front end.
– fernandosavio