I’m trying to get this field (Order Cost) to update when I change the Quantity to reflect the new cost (Qty * Price)
<td class="result" align="right">$<Input type="text" maxLength="9" style="text-align:right; width:55px;" align="right" id="OC<%=i %>" value="<%=formatnumber(rstBevInventory("avg_unit_cost"),2)*proposed %>"/></td>
It calculates the original total, but when I change the Qty, it calls this Javascript function:
function reCalcOrder(i){
document.getElementById("OC"+i).value = document.getElementById("P"+i).value * document.getElementById("Q"+i).value;
cost = document.getElementById("OC"+i).value;
Math.round(cost * 100) / 100;
document.getElementById("OC"+i).set("value", "cost");
if (document.getElementById("Q"+i).value < 0){
document.getElementById("Q"+i).value = 0;
}
}
I get way too many digits, and it seems like this is because of the way Javascript handles multiplication. Is there a way to have the ASP react when the Qty field is changed? Because ASP seems to do the math without issue.
Thanks ahead of time!
Yes, there is, using Ajax. But I believe you’ll also fix if the problem if you change this line:
to
Another option is using
Number.prototype.toFixed: