Home Web Development jQuery Solution to: How do I prevent direct editing in a jQuery datepicker...

Get social!

The common answer on the web for this question is to set the readonly attribute in the input tag:

<input id="my-datepicker" readonly="true" name="thedate" />

This indeed works (for most browsers, anyway). However, the input will usually will be rendered as disabled (grayed out) by the browser, which can be confusing to the user.


Instead, try capturing the keypress event:


The datepicker still fires so the user has the calendar to choose the date.

Bad Behavior has blocked 164 access attempts in the last 7 days.