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.
4 Answers
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
Try this
$(function(){
$('input[type=text]').bind('keyup keydown keypress', function (evt) {
return false;
});
});
2 Comments
Sushanth --
This is an overkill.. Just setting a readonly attribute should do
Amit
@Sushanth-- Yes you are right but he don't want disable in question
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
Anup
for reference : stackoverflow.com/questions/5624988/javascript-disable-textbox
Anup
you post your question in javascript that's why i post answer with javascript solution otherwise @VAGABOND has a right solution
user2450398
Unfortunately its not working. I want to allow only input from barcode scanner. And restrict to any field from keyboard.
Anup
So please mention it in your question, you wrote half of the things you need.............. i am updating my answer one minute
Anup
and my previous answer and this is working well dear just check your code. May be you wrote something wrong there