I have a simple JavaScript function that sums user input. The function is working fine when I tested it without the form tag. But when I use the same code inside the form tag. The console shows the error
TypeError: total is not a function
my code
function total() {
a = Number(document.getElementById('qty').value);
b = Number(document.getElementById('amount').value);
c = a * b;
document.getElementById('totalPrice').value = c;
}
<form>
<div>
<label>Part Quantity</label>
<input type="number" name="quantity" class="form-control" placeholder="Part Quantity" min="1" id="qty" onkeyup="total()">
</div>
<div>
<label>Part Price</label>
<input type="number" name="price" class="form-control" min="1" placeholder="Part Price" id="amount" onkeyup="total()">
</div>
<div>
<label>Total Price(in USD)</label>
<input type="text" name="total" readonly="" class="form-control" min="1" placeholder="Total Price" id="totalPrice">
</div>
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12 order-btn">
<button type="submit" class="btn btn-danger pull-right" name="order">
Order Now
</button>
</div>
</form>
I have tried this aswell
onkeyup="return javascript:total()"
which gives me console error. The syntax is stated javascript function not working in form
SyntaxError: unexpected token: ':'
</form>tag<form >or after</form>tag gives the same error.