Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Javascript from Input Tag

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP with an input box that gets focus onload. I would like to use a handheld scanner to scan a bar code. The scanner has carriage return turned on. I need a javascript to be involked when the bacr code is scanned in without any further user action. Onchange and onblur will not work unless the enter key is pressed so the input box looses focus.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to add a setTimeout/setInterval that looks at the value of the textbox. when the value is different you fire off your method.

Eric
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I have it working but what would you suggest if I want to give the user an option to either scan a bar code or type the number in manually? Right now if I try to type in the timer fires before the entire number is entered.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well detect when the user enters a keypress. If that happens disable the timer functionality.

Eric
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I put a onkeypress on the input box, it fires when I scan a barcode with scanner.
 
Frank Brown
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't say I've tried this, but I would think something like this would work:
Use onkeypress handler to detect carriage return (whether from barcode reader or keyed by user). When CR occurs, set hourglass pointer, disable input, grab current value and submit ajax call. On response from ajax call (confirming action), reset pointer, reset and enable input box, and give focus.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic