alexohneander
alexohneander

Reputation: 559

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).

Upvotes: 4

Views: 22366

Answers (3)

rmabs
rmabs

Reputation: 41

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>

Upvotes: 4

hamed
hamed

Reputation: 8033

You should disable keyboard on your input like this:

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

And Here is a working fiddle.

Upvotes: 6

I&#39;m Geeker
I&#39;m Geeker

Reputation: 4637

Try this prop()

// Disable #x
$( "#x" ).prop( "disabled", true );

// Enable #x
$( "#x" ).prop( "disabled", false );

Upvotes: -1

Related Questions