hey guys, so im trying to auto calculate two textfields. like for example i have textfield A and textfield B and also a <span> tag. the span tag is default zero. when user inputs A as 5 the <span> tag becomes 5. then when user inputs B as 2, A and B auto calculate and <span> becomes 7. but its not working for this coding that i have. it doesnt add up instead it becomes 52 instead of 7. i think the hidden input text is in the way but i dont know how to work around that.
coding:
<html>
<head>
<script type="text/javascript">
function calculateTotal() {
var totalAmt = document.addem.total.value;
totalR = eval(totalAmt + document.addem.tb1.value);
document.getElementById('update').innerHTML = totalR;
}
function calculateTotal1() {
var totalAmt = document.addem.tb1.value;
totalR = eval(totalAmt + document.addem.tb2.value);
document.getElementById('update').innerHTML = totalR;
}
</script>
</head>
<form name="addem" action="" id="addem" >
<span id="update">0</span>
<p><input type="text" name="tb1" onkeyup="calculateTotal()"/>first textbox</p>
<p><input type="text" name="tb2" onkeyup="calculateTotal1()"/>second textbox</p>
<input type="hidden" name="total" value="0" />
</form>
</body>
</html>