user2450398
user2450398

Reputation: 195

Restrict keyboard Input to Textbox JavaScript

How do i restrict user to enter any data from Keyboard to Text-box. Actually my requirement is that, this particular textbox is being used for only scanning purpose. Hence, only scanned data will be entered to this textbox and want to restrict any manually entered data from keyboard.

Upvotes: 1

Views: 5490

Answers (4)

Anup
Anup

Reputation: 3353

If you want to fill data from backend then you can permanently disable for that you just need to add in textbox html readonly and then fill value by

document.getElementById("yourtextbox_id").value="your_scanned_value";

Upvotes: 0

HIRA THAKUR
HIRA THAKUR

Reputation: 17757

SAMPLE FIDDLE

I dont think there is any need of javascript here.

Just use readonly in you html.

 <input value="somevalue" name="meow" readonly>

Thats it.No fancy javascript needed.

Upvotes: 2

Lasitha Benaragama
Lasitha Benaragama

Reputation: 2209

Just disable the textbox and get the value from the backend will solve the issue.

Upvotes: 2

Amit
Amit

Reputation: 15387

Try this

$(function(){
   $('input[type=text]').bind('keyup keydown keypress', function (evt) {
       return false;
   });
});

Demo

Upvotes: 1

Related Questions