How to disable typing in datepicker field

Member Avatar for diafol

Are you talking about a HTML5 datepicker input or a framework/library datepicker e.g. jqueryUI ?

If you're talking about the former - perhaps you need to realise that the user may not be using a browser that displays the datepicker in the way that you think it does. Therefore the user needs a textbox of some description to enter the date. A library picker on the other hand should display in the manner you need, unless js is limited/off.

[datepickerFld].disabled = true;

or for browsers which don't support boolean properties in exact maner please use the following syntax:

[datepickerFld].setAttribute("disabled", "disabled");

Cheers

$('#startdate').keydown(function(e) {
   e.preventDefault();
   return false;
});

$('#enddate').keydown(function(e) {
   e.preventDefault();
   return false;
});
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.