I have this HTML and Java Script. I am setting to display the Total amount of these 3 input field automatically. But it gaves me wrong answer if I use + (adding). I works well if I use * (multiply) or / (devide.) Any one please Help!
Here's my HTML code.
</pre>
<tr>
<td><input type='number' id='amt1' name='amt1' onkeyup='total_amount();' onKeyUp='return numbersonly(event);' class='form-control'></td>
<td><input type='number' id='amt2' name='amt2' onkeyup='total_amount();' onKeyUp='return numbersonly(event);' class='form-control'></td>
<td><input type='number' id='amt3' name='amt3' onkeyup='total_amount();' onKeyUp='return numbersonly(event);' class='form-control'></td>
<td><input type='number' id='total' name='total' class='form-control' readonly='readonly'></td>
</tr>
<pre>
Heres my Java Script...
<script type="text/javascript">
function total_amount()
{
document.getElementById('total').value = document.getElementById('amt1').value + document.getElementById('amt2').value + document.getElementById('amt3').value
}
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8 && unicode!=46 && unicode!=37 && unicode!=27 && unicode!=38 && unicode!=39 && unicode!=40 && unicode!=9){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57)
return false
}
}
</script>
</pre>
"1" + "1" == "11"? Oh, you're adding strings…