I would simply like to prevent users from entering or disable the previous dates in input datetime-local
, is there a way to do this?
Here is what I have done, unfortunately nothing happens on this code:
HTML:
<input type="datetime-local" class="form-control col-md-6" name="book" required>
Script:
<script>
var today = new Date().toISOString().split('T')[0];
document.getElementsByName("book")[0].setAttribute('min', today);
</script>
CodePudding user response:
try this
var today = new Date().toISOString().slice(0, 16);
document.getElementsByName("book")[0].min = today;
<input type="datetime-local" class="form-control col-md-6" name="book" required>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>