View Full Version : dynamic text boxes

08-19-2004, 02:29 PM

I have 3 textboxes which numbers are entered into. Each time a value in any of these changes, I want to add up the total of the 3 boxes and display this (preferably in a non-editable fashion) before clicking my submit button to pass this and other information to the next page.

How to I do this? All advice welcome thanks :)

08-19-2004, 07:54 PM
I would use client side javascript

<script type="text/javascript">

function getSums(a,b,c){
var fields = document.thisForm;
var a = fields.a.value;
var b = fields.b.value;
var c = fields.c.value;
a = 0;
a = parseFloat(a);
b = 0;
b = parseFloat(b);
c = 0;
c = parseFloat(c);
var total = a + b + c;
fields.sum.value = total;
<form name="thisForm">
&nbsp;&nbsp; <input name="a" onBlur="getSums()"> <br>
+ <input name="b" onChange="getSums()"><br>
+ <input name="c" onChange="getSums()"><br>
= <input name="sum" readonly>