raulbaros raulbaros - 3 years ago 151
HTML Question

Prevent an input type box from being typed in

I have a datepicker with input box. When clicking the box, the calendar widget (Bootstrap Datepicker) shows. I want to prevent that a user can type anything in the box, meaning he is forced to select from the calendar. How to do?
I tried using 'disable' but that disables it all.



<div class="input"><label for="date posted">Date posted</label>
<input class='datepicker' id="date-posted" name="date-posted" placeholder="Enter your date posted" required="" type="text"></div>




Answer Source

Just disable the keydown event:

<input onkeydown="return false" class='datepicker' id="date-posted" name="date-posted" placeholder="Enter your date posted" required="" type="text"></div>

Or if you are using that bootstrap picker then you can make the input readonly and enable the flag of enableOnReadOnly

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download