Hello,

I wanna ask about scan card. Is there any way to disallow keyboard input and only allow scan card input to key in a field?
FYI, I am using vbscript, html and javascript for this program. So, may be doing something with the javascript?
How about limit the time of input? I really have no idea.


Thank you so much

Recommended Answers

All 5 Replies

Member Avatar for stbuchok

One way I have gotten it to work is as follows:

Have a button (Scan Card)
Click the Scan Card button to have a popup window show up.
The popup window sets focus to a textbox with a width and height of 0px (setting display: hidden will throw security errors later)
Swipe the card
The input is put into the textbox
Create functions to parse the output that is put to the textbox (most cards have a predefined number of characters per line)
When the scan is complete (You will need to determine the condition at which you can say it is complete, x number of character per line) fill in the form in the parent window.

I have implemented this for a Canadian driver's license in an app. I am not allowed to share the code but can assure you it can be done.

Avocado_juice,

Now I have read stbuchok's answer, I think I better understand the problem however I would approach it differently, without needing to use a popup window.

Assuming you already have the means to get the scan process to populate an HTML <input> field, then all you need is a way to prevent the field from accepting keyboard input.

The most obvious approach is simply to disable the field:

<input type="text" name="myField" disabled="disabled" />

However, disabled fields are not included when a form is submitted.

There are several approaches to overcome this.

1. Don't disable the field but prevent it from taking focus.

onload = function() {
  document.myform.myField.onfocus = function(){ this.blur(); };
}

2. Enable the disabled field immediately before the form is submitted.

onload = function() {
  document.myform.onsubmit = function() {
    this.myField.disabled = false;
  };
};

3. Copy the disabled field's value to a hidden field immediately before the form is submitted.

<input type="text" name="myField" disabled="disabled" />
<input type="hidden" name="myHiddenField" />
onload = function() {
  document.myform.onsubmit = function() {
    this.myHiddenField.value = this.myField.value;
  };
};

Airshow

Thanks a lot to stbuchok and Airshow. I tried using time as the limit and it works too. I use setTimeout() and set the time to 300milliseconds. When user keys in in more than 300milliseconds, the textbox is set to blank. It prevents user to key in manually.


Thanks for your help!

Have you checked if somebody paste the number then what happens?

sorry, I didn't think about that. but they don't use computer keyboard to key in the number (so they don't have copy paste button). The keyboard only has numbers and enter button

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.