- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello. I'm trying to implement two barcode scanners to two buttons. The problem is that when I click one button or the other, both scripts for the scanners are activated. How to fix that one button uses one script and the other uses the other script?
Button1:
<a class="uib-graphic-button default-graphic-sizing default-image-sizing hover-graphic-button active-graphic-button default-graphic-button default-graphic-text widget uib_w_52 d-margins skenavimo_tekstas media-button-text-bottom" data-uib="media/graphic_button" data-ver="0" id="scan1" style="position: relative; display:block; float:center; width: 10%; padding-bottom: 10%; width: 50%; margin: 0 auto; " onclick="scanNow();"> <img src="images/barcode.png"> <span class="uib-caption">Check</span> </a>
Button2:
<a class="button widget uib_w_54 d-margins testas icon camera yellow" data-uib="app_framework/button" data-ver="1" id="scan2" onclick="scanNow2();">Scan</a>
Here is the first script:
<script> function scanNow() { //this function launches the QR Code scanner. intel.xdk.device.scanBarcode(); } document.addEventListener("intel.xdk.device.barcode.scan",function(evt){ if (evt.success == true) { //successful scan alert("I'm number 1"); } else { //failed scan alert("ERROR"); } },false); </script>
And here is the second script:
<script> function scanNow2() { //this function launches the QR Code scanner. intel.xdk.device.scanBarcode(); } document.addEventListener("intel.xdk.device.barcode.scan",function(ted){ if (ted.success == true) { //successful scan alert("I'm number 2"); }else{ alert("ERROR"); } },false); </script>
- Tags:
- HTML5
- Intel® XDK
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That is cause u have 2 event handlers already fired and the code is rightly executing both event handlers.
You can do something like this:
<script> var scan = 0; function scanNow(){ scan = 1; intel.xdk.device.scanBarcode(); } function scanNow2(){ scan = 2; intel.xdk.device.scanBarcode(); } document.addEventListener("intel.xdk.device.barcode.scan",function(ted){ if (ted.success == true) { if(scan == 1){ scan = 0; alert("I'm number 1"); } else if(scan == 2){ scan = 0; alert("I'm number 2"); } }else{ alert("ERROR"); } },false); </script>

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page