I trying to do a dynamic multiplication in a textbox. Right now I only figure out to do add. please take a look at my js code. I want to multiply the 2 values.
Here's my code:
<form name="submitform">
<table>
<tr id="service">
<td>
<span>Amount:</span>
</td>
<td>
<input type="text" name="amount" class="amount" onkeyup="onkeyupsum()" autocomplete="off" />
</td>
<td>
<span>Width: </span>
</td>
<td>
<input type="text" name="amount" class="amount" onkeyup="onkeyupsum()" autocomplete="off" />
</td>
</tr>
<tr>
<td>
<h4>Total Amount</h4>
</td>
<td>
<input type="text" name="tamt" id="tamt" />
</td>
</tr>
</table>
</form>
JavaScript code (in HTML):
function onkeyupsum() { // calculate sum and show in textbox
var sum = 0,
amount = document.querySelectorAll('.amount'), i;
for (i = 0; i < amount.length; i++) {
sum += parseFloat(amount[i].value || 0);
}
document.submitform.tamt.value = sum;
}