I am trying a pass an array consisting of barcode scanned code in my barcode scannin app using phonegap plugins. I am getting an error "Uncaught TypeError: Cannot set property 'innerHTML' of null ". In the following code I have used a var k=0;
and have declared an array var code= new Array(100);
in the javascript file previously.
here is my html file
<!doctype html>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
<script type="text/javascript" src="barcodescanner.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<p />
<p />
<div ng-controller="controller">
<table ng-repeat="result in results">
<tr>
<td>
S.No
</td>
<td >
Barcode
</td>
</tr>
<tr>
<td >
1
</td>
<td
id="d">
</td>
</tr>
<tr>
<td >
2
</td>
<td
id="code[0]">
</td>
</tr>
<tr>
<td >
3
</td>
<td
id="code[1]">
</td>
</tr>
<tr><td><input class="butt" type="button" value="New Scan" onclick="scanCode();" /></td></tr>
</body>
<script type="text/javascript">
var barcodeVal = localStorage.getItem("myvalue");
document.getElementById("d").innerHTML = barcodeVal;
</script>
<script type="text/javascript">
var scanCode = function () {
window.plugins.barcodeScanner.scan(
function (result) {
alert("Scanned Code: " + result.text + ". Format: " + result.format + ". Cancelled: " + result.cancelled);
localStorage.setItem("myvalue1", result.text);
window.location.href = 'page5.html';
}, function (error) {
alert("Scan failed: " + error);
});
}
</script>
<script type="text/javascript">
var barcodeVal = localStorage.getItem("myvalue1");
document.getElementById("code[k]").innerHTML = barcodeVal;
k=k+1;
</script>
</html>
In the following code i am tryin to scan barcode again and again and store the values in an array code[]
. But i am getting the error. plz help me. How should i solve the following issue.I am using phonegap-1.4.1 and barcode scanning plugin for android.Thanks in advance.