Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery mobile javascript calculator
    text
    copied!<p>I am very new to javascript, and I am trying to build a mobile app with Jquery Mobile. I would like the user to input one value on each page and then on the last page they will click submit and it will display the value on the last page. I have been working on this for like 4 hours and I can get the calculation to work on the same page as the submit button but not on the next page.</p> <pre><code> &lt;script&gt; function sum() { var item1num = document.getElementById('item1num').value; var item2num = document.getElementById('item2num').value; {result = parseInt(item1num)*parseInt(item2num); document.getElementById("showResult").innerHTML = (result);}} &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- Home --&gt; &lt;div data-role="page" id="page1"&gt; &lt;div data-role="content"&gt; &lt;div data-role="fieldcontain" id="item1"&gt; &lt;fieldset data-role="controlgroup"&gt; &lt;label for="item1"&gt; item1 &lt;/label&gt; &lt;input name="item1num" id="item1num" placeholder="" value="" type="number" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;a data-role="button" data-transition="slidefade" href="#page2" data-theme="b"&gt; Next &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="page" id="page2"&gt; &lt;div data-role="content"&gt; &lt;div data-role="fieldcontain" id="item1"&gt; &lt;fieldset data-role="controlgroup"&gt; &lt;label for="item2"&gt; item2 &lt;/label&gt; &lt;input name="item2num" id="item2num" placeholder="" value="" type="number" /&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;input id="btnAdd" type="submit" value="Submit" onclick="sum();" data-theme="b" /&gt; &lt;span id="showResult"&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="page" id="page3"&gt; &lt;div data-role="content"&gt; &lt;span id="showResult"&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload