Phonegap: my Javascript code works on browsers, but it does not work on the emulator or Android device

advertisements

I'm trying to make an Android App using phonegap and JQuery Mobile.

I have a div that shows a value. That value is changed whenever I click on the checkbox by adding or subtracting the div's value from the labels value

This is my index file which I install on the Android Device.

<head>
 <script>
  function inputData(idVar)
 {
 var myId;
 myId = document.getElementById(idVar).getAttribute("value");
 var myTag = document.getElementById(idVar);

 var mymyTag = myTag.querySelectorAll(".ui-btn-text");
 var myData = mymyTag[0].innerHTML;
 var myDataParsed = parseInt(myData);
if (document.getElementById(myId).checked==false)
 {
 myDataPrased =  myDataParsed+parseInt(document.getElementById("input_label").innerHTML);
 document.getElementById("input_label").innerHTML=myDataPrased;
 }
 else
 {
 var myResult
 var myOldData = parseInt(document.getElementById("input_label").innerHTML);
 myResult = myOldData-myDataParsed;
 document.getElementById("input_label").innerHTML=myResult;
 }
 }

  </script>
  </head>

<body>
<div data-role="page" id="input">
<div data-role="header"></div>
  <div data-role="content">

    <div data-role='fieldcontain' align="center">
    <fieldset data-role='controlgroup' id="in">
    </fieldset>
    </div>
    <div id="input_label">0</div>
     <a href="#data" data-role="button" data-inline="true">Back</a>
</div>
<div data-role="footer" data-position="fixed">
    <h4>Page Footer</h4>
</div>

The Checkboxes are generated from a php page. and insearted in

 <fieldset data-role='controlgroup' id="in">

The function "inputData" is called when I click the label (In JQuery Mobile the label tag seems to cover the CheckBox, so when I think I'm clicking the checkbox, I'm actually clicking on the label and then it will generate an event that will trigger the Checkbox)

the function will receive the ID of the label. Then using it, I get the ID of CheckBox by extracting it from the "value" attribute of the label tag, so I can use it to check for the if the CheckBox is checked or not.

This code runs perfectly on a Web Browser like FireFox. But it doesn't run it when I install it on Android Device using Eclipse. No matter how I click on the Checkbox. the value of the div doesn't change.


I was able to fix my issue by turning around. Instead of checking onclick events on the checkboxes and changing the value. I made a button called "calculate", which iterate on all the checkboxes and calculate the value of the checked ones. then editing the final value through onclick event on that button.

Thank you very much for everyone tried to help me, I appreciate it.