Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add numeric values dynamically without hitting the 'Submit' button? (version 1)

Add numeric values together

How do I add numeric values dynamically without hitting the 'Submit' button? (version 1)

by  GUJUm0deL  Posted    (Edited  )
<script language="javascript" type="text/javascript">
function addd() {
document.addem.input1.value= ""
document.addem.input2.value= ""
}

function addthem() {
//FIRST INPUT VALUE
var add1 = document.addem.input1.value
var add1 = parseFloat(add1, 10)
add1 = (isNaN(add1))?0:add1;

//SECOND INPUT VALUE
var add2 = document.addem.input2.value
var add2 = parseFloat(add2, 10)
add2 = (isNaN(add2))?0:add2;

//ADD THEM TOGETHER
return eval(add1) + eval(add2);
}

function addition() { document.addem.answer.value = addthem() }
// -->
</script>

<form name="addem">
<table border="0" cellpadding="2">
<tr><td colspan="3"><p>Enter any number. Numbers get added up upon every move. Fields can be left blank!!</p></td></tr>
<tr>
<td>add: <input type="TEXT" name="input1" onChange="addition(addem)" size="20" maxlength="10"></td>
<td>add: <input type="TEXT" name="input2" onChange="addition(addem)" size="20" maxlength="10"></td>
<td>answer: <input type="TEXT" name="answer" onFocus="this.blur();" size="20" maxlength="10"></td>
</tr>
</table>
</form>
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top