...

View Full Version : dynamic text boxes



newbieasper
08-19-2004, 01:29 PM
Hey,

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 :)

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



<html>
<head>
<title></title>
<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;
if(!a){
a = 0;
}else{
a = parseFloat(a);
}if(!b){
b = 0;
}else{
b = parseFloat(b);
}
if(!c){
c = 0;
}else{
c = parseFloat(c);
}
var total = a + b + c;
fields.sum.value = total;
}
//-->
</script>
</head>
<body>
<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>
</form>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum