Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a simple update to what you have that works. Part of your question was to avoid page reloading, so you will notice the FORM no longer does a POST action and your SUBMIT BUTTON is no longer an input but a standard button with an onClick action. This will allow everything to execute without navigating away from the page. For the sake of time I put the results addition in a separate table, feel free to style how you wish.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Order&lt;/title&gt; &lt;script type="text/javascript"&gt; var qtyTotal = 0; var priceTotal = 0; function updateForm() { var product = document.getElementById("product").value; var qty = document.getElementById("quantity").value; qtyTotal = qtyTotal + parseInt(qty); document.getElementById("qtyTotals").innerHTML=qtyTotal; var price = document.getElementById("price").value; priceTotal = priceTotal + parseInt(price); document.getElementById("priceTotals").innerHTML=priceTotal; var table=document.getElementById("results"); var row=table.insertRow(-1); var cell1=row.insertCell(0); var cell2=row.insertCell(1); var cell3=row.insertCell(2); cell1.innerHTML=product; cell2.innerHTML=qty; cell3.innerHTML=price; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="order" id="order"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;label for="product"&gt;Product:&lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="product" name="product" title="Please enter only alphabetic characters" type="text" size="28" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;label for="quantity"&gt;Quantity:&lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="quantity" name="quantity" title="Enter item quantity" width="196px" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;label for="price"&gt;Price:&lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="price" name="price" title="Please enter only numeric characters" size="28" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="reset" name="reset" id="resetbtn" class="resetbtn" value="Reset" /&gt; &lt;button type="button" onClick="updateForm();"/&gt;Add To Table&lt;/button&gt; &lt;/form&gt; &lt;br&gt; &lt;table id="results" width="360"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th scope="col" width="120"&gt;Products&lt;/th&gt; &lt;th scope="col" width="120"&gt;Quantity&lt;/th&gt; &lt;th scope="col" width="120"&gt;Price&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;/table&gt; &lt;table id="resultTotals" width="360"&gt; &lt;tr&gt; &lt;td scope="col" width="120"&gt;Totals&lt;/td&gt; &lt;td scope="col" width="120"&gt;&lt;div id="qtyTotals"&gt;&lt;/div&gt;&lt;/td&gt; &lt;td scope="col" width="120"&gt;&lt;div id="priceTotals"&gt;&lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p>Here is <a href="http://jsfiddle.net/gXVs3/3/" rel="nofollow">JS Fiddle Example of above code.</a></p>
 

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