javascript - Uncaught TypeError: Cannot set property 'innerHTML' of null -


i making barcode scanning app using phonegap-1.4.1 android. need define n array code[] can store barcode text scanned , need define variable k act counter incremented 1 after every scan can store detail in code[k]. here previous javascript file have defined array , variable counter.

     localstorage["counter"]=0;      var code = new array(100);      localstorage.setitem("code", json.stringify(code)); 

and here js file calling stored array , printing value stored in array "id". myvalue1 barcode text obtained scan.

   var barcodeval = localstorage.getitem("myvalue1");    var test2 = localstorage.getitem("code");    code = json.parse(test2);    var k = parseint(localstorage.getitem("counter"));    code[k] = "code[k]";    document.getelementbyid(code[k]).innerhtml = barcodeval;    k = k + 1;    localstorage["counter"]=k;    localstorage.setitem("code", json.stringify(code)); 

i calling barcode scan function again , again. thats why using array storing data of barcode scanned.here scan js file gives value of myvalue1

 <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);        });   } 

i getting error uncaught typeerror: cannot set property 'innerhtml' of null. new phonegap , coding . please me out issue. in advance.

you don't need keep track of variable k. simple manage barcode values using below script.

please check below jsfiddle...run twice can see difference.

jsfiddle

<script> function savedatatolocalstorage(barcodevalue) {      var olditems = json.parse(localstorage.getitem('barcodes')) || [];     var newitem = {         'barcode': barcodevalue     };     olditems.push(newitem);     localstorage.setitem('barcodes', json.stringify(olditems));  } savedatatolocalstorage("123456879ffgg"); </script> 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -