最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Restrict keyboard Input to Textbox JavaScript - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Aug 9, 2013 at 5:33 user2450398user2450398 1951 gold badge7 silver badges17 bronze badges 1
  • 1 Can we see some code of what you are doing? – rink.attendant.6 Commented Aug 9, 2013 at 5:39
Add a ment  | 

4 Answers 4

Reset to default 2

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

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.

Try this

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

Demo

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";
发布评论

评论列表(0)

  1. 暂无评论