1

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.

1
  • 1
    Can we see some code of what you are doing? Commented Aug 9, 2013 at 5:39

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

Try this

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

Demo

2 Comments

This is an overkill.. Just setting a readonly attribute should do
@Sushanth-- Yes you are right but he don't want disable in question
0

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";

5 Comments

you post your question in javascript that's why i post answer with javascript solution otherwise @VAGABOND has a right solution
Unfortunately its not working. I want to allow only input from barcode scanner. And restrict to any field from keyboard.
So please mention it in your question, you wrote half of the things you need.............. i am updating my answer one minute
and my previous answer and this is working well dear just check your code. May be you wrote something wrong there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.