• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running Javascript from Input Tag

 
Ranch Hand
Posts: 2211
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2211
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2211
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I put a onkeypress on the input box, it fires when I scan a barcode with scanner.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic