javascript - Storing id in arrays and using it for printing -
i new coding. trying make barcode scanning app , can scan multiple barcodes. trying store data in array code[]
, printing data in html. have defined code[]
array , counter in different js file as
localstorage["counter"]=0; var code = new array(); localstorage.setitem("code", json.stringify(code)); `
and here page5.html
file . in following code myvalue
value getting different code. problem myvalue1
. trying call function again , again different value of myvalue1
, store in array code[]
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script language="javascript" type="text/javascript" src="/js/jquery.js"></script> <link rel="stylesheet" href="jquery.mobile/jquery.mobile-1.0rc2.css" type="text/css" charset="utf-8" /> <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> <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'; var barcodeval = localstorage.getitem("myvalue1"); var test2 = localstorage.getitem("code"); code = json.parse(test2); var k = parseint(localstorage.getitem("counter")); alert(k); $("#code[k]").text(barcodeval); k++; localstorage["counter"] = k; localstorage.setitem("code", json.stringify(code)); }, function(error) { alert("scan failed: " + error); }); } </script> </html>
i dont know going wrong , array not able print data in table. please help. in advance
your jquery selector wrong instead of
$("#code[k]").text(barcodeval);
it should
$("#code["+k+"]").text(barcodeval);
to work properly. , couldn't r u tryin u updating array. hope helps.
Comments
Post a Comment