DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Calculating Sum Of 2 Form Fields Using Javascript
Automatically adds two fields together (text fields), without the need for a submit or input button.
<script type="text/javascript"><!--
function updatesum() {
document.form.sum.value = (document.form.sum1.value -0) + (document.form.sum2.value -0);
}
//--></script>
<body>
<form name="form" >
Enter a number:
<input name="sum1" onChange="updatesum()" />
and another number:
<input name="sum2" onChange="updatesum()" />
Their sum is:
<input name="sum" readonly style="border:0px;">
</form>
</body>





