javascript - how to store values in an array -
in following code getting scanned value of barcode.
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'; var barcodeval = localstorage.getitem("myvalue1"); var test2 = localstorage.getitem("code"); code = json.parse(test2); var k = parseint(localstorage.getitem("counter")); document.getelementbyid(code[k]).innerhtml = barcodeval; alert(code[k]); alert(k); k++; localstorage["counter"] = k; localstorage.setitem("code", json.stringify(code)); }, function (error) { alert("scan failed: " + error); });
myvalue1
value getting scanning . have defined array , counter in js file as
localstorage["counter"]=0; var code = {}; localstorage.setitem("code", json.stringify(code));
now trying store id in array code[]
, trying print in page5.html
. above <script>
defined in same page5.html
. calling scan function again , again multiple barcode scanned. printing value in html as
<tr> <td>2</td> <td id="code[0]"></td> </tr>
i getting error cannot set property 'innerhtml' of null
. should next? please me. in advance
as can see jsfiddle here when code[k] in instruction
document.getelementbyid(code[k]).innerhtml = barcodeval;
code not understood array of strings string, poining @ code[0] not point id bracket.
do json.parse() on code in updated jsfiddle here
Comments
Post a Comment