Hello!!!

I am having trouble with the focus() function in one of my js/jquery
scripts.
I want to have an input field that will "listen" to any info coming in
from a barcode scanner. It should work like this:
- page loads, focus is set to my "scannerInput" field,
- user scans a barcode, the code is copied to the input field,
- onChange is triggered (I checked, the scanner triggers onChange),
- some processing is done with the data from the scanner
- input is cleared
- focus set to input so it can recieve another barcode

Here's my HTML:
<input type="text" name="scannerInput" id="scannerInput" style=""
size="25" value=""  />

Here's my js:

function barcodeScanned() {
        var theinput = $j('input#scannerInput');
        someprocessing();
        theinput.attr('value', '');
        theinput.focus();
}

function jQueryInit()
{
   $j('input#scannerInput').focus();
   $j('input#scannerInput').bind('change', barcodeScanned);
}

var $j = jQuery.noConflict();
$j('document').ready(jQueryInit);


Unfortunately this does not work. It does nothing whatsoever (the
focus bit). I tried linking focus() to other links/buttons and it
works fine, but for some reason it will not work with the onChange
bit.
Does anyone have a clue how to fix this? Or perhaps you have a better
solution to the whole problem.
I would like to avoid making the user click anywhere before using the
scanner. It would work - make a button that will clear the input and
set the focus, but that kind of solution would be really a last resort
for me.

Any help appreciated,

Best regards,

Szymon

Reply via email to