I'm doing a simple calculation by receiving the data from previous page. Here is the first page and it is sending the data after click check out.
<script>
function passValues() {
var bp = document.getElementById("Amount_BP").value;
localStorage.setItem("bp_value", bp);
return false;
}
</script>
<form action="settlement.aspx">
<table style="width:60%";>
<tr>
<td>
Black pepper sauce
<br />
Amount: <input type="number" id="Amount_BP" value="0" style="margin-top: 5px" />
</td>
</tr>
</table>
</form>
<button type="button" class="settlement button_press" onclick="settlement(); passValues();">Check Out</button>
And the second page is the settlement so it will receive the amount from the previous page. And I want make it the calculation auto complete after receive data. The script below the table is receive data script.
<table style="width:90%">
<tr>
<th> </th>
<th>Type</th>
<th>Quantity</th>
</tr>
<tr>
<td><img src="Image/chicken_chop.png" style="height: 100px; width: 200px"/></td>
<td style="text-align: center">Black Pepper Sauce</td>
<td style="text-align: center"><p id="Amount_bp" onchange="autoCal(this.value)">0</p></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><input class="w3-input w3-border" name="tot_amount" id="total" type="text" readonly/></td>
</tr>
</table>
<script>
document.getElementById("Amount_bp").innerHTML = localStorage.getItem("bp_value");
</script>
And the last one is my script file that I created for both
function settlement () {
window.location.href = 'settlement.aspx';
}
function autoCal(val) {
var tot_price = val * 14.9;
/*display the result*/
var divobj = document.getElementById('total');
divobj.value = tot_price;
}
At the last, I think that it is work for me as I expect the data send to another page and it will auto calculate but it fail. I think my problem is on function autoCal(Val) that part but I can't find the mistake I made
document.getElementById('total').value = tot_priceis correct, but why is there a onchange on a P?