I've tried several solutions of a similar problem, but it's not working in my program. I want the book code in the qr code to appear on select2 search when it is scanned. This works when using input tags, but doesn't work when using select2.
This is my code below :
<script type="text/javascript">
let scanner = new Instascan.Scanner({
video: document.getElementById('preview')
});
startWebcam = function() {
Instascan.Camera.getCameras().then(function(cameras) {
if (cameras.length > 0) {
scanner.start(cameras[0]);
} else {
console.error('No Cameras Found');
}
}).catch(function(e) {
console.error(e);
});
//its not working
scanner.addListener('scan', function(content) {
// alert(content);
// $("#qrcode").val(content);
$('#qrcode').select2();
$("#qrcode").val("content").trigger("change");
});
}
stopWebcam = function() {
scanner.stop();
}
</script>
<select id="qrcode" style="width: 100%;" name="id_buku" class="form-control select2" required>
<option value="">-- Silahkan Pilih Buku --</option>
<?php foreach ($buku as $b) { ?>
<option value="<?= $b['id']; ?>"><?= $b['no_inven'] . ' - ' . $b['judul']; ?></option>
<?php } ?>
</select>