aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Running Javascript from Input Tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Running Javascript from Input Tag" Watch "Running Javascript from Input Tag" New topic
Author

Running Javascript from Input Tag

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1490
    
    1
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Nov 16, 2004
Posts: 1490
    
    1
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well detect when the user enters a keypress. If that happens disable the timer functionality.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1490
    
    1
If I put a onkeypress on the input box, it fires when I scan a barcode with scanner.
Frank Brown
Greenhorn

Joined: Jan 22, 2004
Posts: 6
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.


"Make things as simple as possible, but no simpler." - A.Einstein
 
 
subject: Running Javascript from Input Tag