I'm building a simple checkout page with on the left side a box with the prices and on the right the payment form. I'm trying to get the cart total to also print on an input field in the payment form. I tried to change the id cartTotal for a class so that the input field can also have the class "cartTotal". Doing so just mess with the entire script. The numbers wont show up.
ApplyTax Script:
<script>
function applyTax() {
var cartSubTotal = parseFloat(document.getElementById('cartSubtotal').innerHTML);
console.log(cartSubTotal);
var salesTaxGst = (cartSubTotal / 100) * 5;
var salesTaxPst = (cartSubTotal / 100) * 9.975;
var totalAmount = (cartSubTotal * 1) + (salesTaxGst * 1) + (salesTaxPst * 1);
document.getElementById('cartSubtotal').innerHTML = cartSubTotal.toFixed(2);
document.getElementById('taxGst').innerHTML = salesTaxGst.toFixed(2);
document.getElementById('taxPst').innerHTML = salesTaxPst.toFixed(2);
document.getElementsByClassName('cartTotal').innerHTML = totalAmount.toFixed(2);
}
// Call the applyTax() when the window finishes loading...
window.onload = function() {
applyTax();
}
</script>
The Payment Form:
<form method="post" action="purchase" name="checkout">
Total
<input maxlength="6" type="text" class="cartTotal" name="x_amount" size='9' readonly value="${cart.total}" />
<br>
<br>
<p>
<fmt:message key='CreditNumber' /> </big><big><br>
<input maxlength="20" size="30" name="cc_number"></big>
<br>
<br>
<big><fmt:message key='NameCard'/> </big><big><br>
</form>
This not work, the fields return blank, what am I doing wrong?