0

I have been asked for a very short simple project to allow the magnetic stripe of an ID card to be read, and display the result from a database if dues are paid or not paid.

I have all this working and am trying to remove some annoying behaviors. The magnetic strip information is being captured in a form with a single input text field. The user must click on submit to proceed to a second hidden page where I parse out the information and assign to variables, preparing for the database search.

I would like to remove the requirement that the user has to press the submit button. It seems that I should be able to trigger off the length of the input variable being greater than 0.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

. .

<body onload = document.get_id.fID_Num.focus();>

. .

<form id="get_id" name="get_id" method="post" action="card_swipe_process.asp">
  <table width="100%" border="5" cellpadding="2">
      <tr>
          <td width="45%" class="PIN_LABEL">Swipe ID Card</td>
          <td width="10%">&nbsp;</td>
          <td width="45%"><label for="fID_Num"></label>
          <input name="fID_Num" type="text" id="fID_Num" maxlength="15" /></td>
      </tr>
      <tr>
          <td class="PIN_LABEL">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
      </tr>
      <tr>
          <td class="PIN_LABEL">&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="submit" name="ID_NUM_ENTER" id="ID_NUM_ENTER"              value="Submit" /></td>
      </tr>
  </table>
</form>
Michaël
  • 3,679
  • 7
  • 39
  • 64
  • 1
    It would be nice to, at the very least, wrap the `onload` attribute in quotes. – John Dvorak Dec 13 '12 at 14:55
  • 4
    Please show use **how** "*the magnetic strip information is being captured in the input text field*". We might find a working event for you then. Also, what browser/environment does the client use? – Bergi Dec 13 '12 at 14:58

3 Answers3

2

I'm assuming you have code somewhere that reads in the card number and puts it in the box. Just add document.getElementById('get_id').submit() to that code. This way, the user can still type in a number if needed.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
2

I had exactly the same problem with a barcode reader that acted as a "keyboard wedge".

Start a timer for 300ms. After each "keystroke" clear and restart the timer. Once the timer times out, submit the form.

See: How can I call a function after a person stops typing?

var timer;

function onKeyUpHandler(e){
    timer = setTimeout(function() {document.get_id.submit()}, 300)    
}

function onKeyDownHandler(e) {
    clearTimeout(timer);
}
Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
1
<script>
function sub(){
var id = document.getElementById('ID_NUM_ENTER').value;
if(id.length >= 0)
document.getElementByTagName('form').submit();
</script>

This has to work and i suggest here using ajax when you are dealing with database and it works faster.