0
Answered

OnChange event does not fire when barcode scanner result is returned to a text box

Richard 1 year ago in Application • updated 1 year ago 1

We inject the following JavaScript after a barcode scan:


document.getElementById('testinput').value='value';

However jQuery will not detect this as a value change (happens when tested on Chrome too).


Instead we call the "onchange" function of the input field, for example your page would contain the below:


<a href="#" onclick="javascript:openAndroidBarcodeScannerInput('testinput');">Open Barcode Scanner - input field ID * Requires 2.0.7 or higher</a>
<input type="text" id="testinput" value="" onchange="onTestInputChange()">
<script>
      function onTestInputChange() {
        alert('.change() for testinput, value = ' + $('#testinput').val());
    }
</script>

Kiosk Browser then injects the following code after a successful barcode scan.


document.getElementById('testinput').value='test';
if (document.getElementById('testinput').onchange != null) {
    document.getElementById('testinput').onchange();
}

You can test this via our sample JavaScript page http://www.android-kiosk.com/jstest.htm