I'm trying to use sessionStorage to pass information from a merchandise page to shopping cart page, which displays what items were purchased, how many items were purchased, cost of item, cost of subtotal, cost of total before taxes, the tax amount and after taxes. It displays the monetary value of each item, but an undefined output in "Quantity" and a NaN in "Subtotal", before taxes, tax amount and after taxes. Here's a sample of my code:
<script>
var cart7 = 4.95;
function findTotal()
{
document.getElementById("cart7").value = cart7;
document.getElementById("product1").value = sessionStorage.get1;
document.getElementById("price1").value = cart7 * sessionStorage.get1;
var beforeTax = parseInt(document.getElementById("price1").value) + parseInt(document.getElementById("price2").value) + parseInt(document.getElementById("price3").value) + parseInt(document.getElementById("price4").value) + parseInt(document.getElementById("price5").value) + parseInt(document.getElementById("price6").value);
document.getElementById("beforeTax").value = beforeTax;
var taxAmount = parseFloat(beforeTax * 0.074);
document.getElementById("taxAmount").value = taxAmount.toFixed(2);
var afterTax = beforeTax + taxAmount;
document.getElementById("afterTax").value = afterTax;
}
<script>
<body onload="findTotal()">
<table>
<tr style = "text-align:center">
<td>
<h3>Product</h3>
</td>
<td>
<h3>Quantity</h3>
</td>
<td>
<h3>Price</h3>
</td>
<td>
<h3>Subtotal</h3>
</td>
</tr>
<tr style = "text-align:center">
<td>
We Will All Go Together sheet music
</td>
<td>
<input type="text" value="0" id="product1" size="5" />
</td>
<td>
$<input type="text" value="0" id="cart7" size="5" />
</td>
<td>
$<input type="text" value="0" id="price1" size="5" />
</td>
</tr>
<tr style = "text-align:center">
<td>
Total (before taxes):<br />
</td>
<td>
<p><input type="text" value="0" id="beforeTax" size="5" /></p>
</td>
<tr style = "text-align:center">
<td>
Tax:<br />
</td>
<td>
<p><input type="text" value="0" id="taxAmount" size="5" /></p>
</td>
</tr>
<tr style = "text-align:center">
<td>
Total (after taxes):<br />
</td>
<td>
<p><input type="text" value="0" id="afterTax" size="5" /></p>
</td>
</tr>
</body>