I have a jquery Datetimepicker and i want to disable the keyboard input. I want only edit this field over the picker (Modalbox).
Asked
Active
Viewed 2.2k times
4
-
2Have you tried `readonly="readonly"` for the date element ? – Pramod Karandikar Mar 12 '15 at 10:54
-
2did you try using `readonly="readonly"`? – briosheje Mar 12 '15 at 10:55
-
possible duplicate of [JQuery Datepicker with text input that doesn't allow user input](http://stackoverflow.com/questions/153759/jquery-datepicker-with-text-input-that-doesnt-allow-user-input) – Saif Mar 12 '15 at 11:30
-
readonly makes the field disabled for editing. He juat wants to disable the keyboard not the field, probably for getting a proper datetime format. Because it will be accurate if selected using datepicker button or icon. – Irfan wani Dec 21 '20 at 03:32
3 Answers
6
You should disable keyboard on your input like this:
$(function() {
$('#datepicker').keypress(function(event) {
event.preventDefault();
return false;
});
});

hamed
- 7,939
- 15
- 60
- 114
4
readonly
attribute on the text input should work for you, use this property in input field either by manually entering or you can set this attribute using Javascript or jQuery.
Set a text field to read-only using Script:
document.getElementById("myText").readOnly = true;
Or in HTML:
<input type="text" name="textName" placeholder="Select date" readonly>
-1
Try this prop()
// Disable #x
$( "#x" ).prop( "disabled", true );
// Enable #x
$( "#x" ).prop( "disabled", false );

I'm Geeker
- 4,601
- 5
- 22
- 41