Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Keyboard in Input Textfield

I have a jquery Datetimepicker and i want to disable the keyboard input. I want only edit this field over the picker (Modalbox).

like image 854
n00dle Avatar asked Feb 10 '23 16:02

n00dle


2 Answers

You should disable keyboard on your input like this:

$(function() {
   $('#datepicker').keypress(function(event) {
       event.preventDefault();
       return false;
   });
});

And Here is a working fiddle.

like image 138
hamed Avatar answered Feb 13 '23 05:02

hamed


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>
like image 28
rmabs Avatar answered Feb 13 '23 05:02

rmabs