B
Building Blocks
I have this javascript written form calculator that just adds numbers from
blank text fields and enters into a seperate text field the total. What I
would like is for this form calculator to include radio buttons, checkbox,
and dropdowns. Right now if I include this in this script (I add the number
to value="") none of these, except for a simple text field works. Any help
would be GREATLY appreciated.
Here is the script that I'm using:
<html>
<head>
<title></title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function sumIt() {
var f = document.forms["myForm"]
var s = 0
for (var i=1;i<=4;i++) {
var v = f.elements["Val"+i].value
v = parseFloat(v)
if (isNaN(v)) continue
v = Math.abs(v)
s+=v
}
f.elements["exptotal"].value = s
}
//-->
</SCRIPT>
</head>
<body>
<form name="myForm">
<p>
one: <input type=text name="Val1" onchange="sumIt()">
</p>
<p>
two: <input type=text name="Val2" onchange="sumIt()">
</p>
<p>
three: <input type=text name="Val3" onchange="sumIt()">
</p>
<p>
four; <input type=radio name="Val4" onchange="sumIt()">
</p>
<p>
Suma:<input type="text" READONLY class="disabled" name="exptotal" size="20"
value="0.00">
</p>
</form>
</body>
</html>
-------------
blank text fields and enters into a seperate text field the total. What I
would like is for this form calculator to include radio buttons, checkbox,
and dropdowns. Right now if I include this in this script (I add the number
to value="") none of these, except for a simple text field works. Any help
would be GREATLY appreciated.
Here is the script that I'm using:
<html>
<head>
<title></title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function sumIt() {
var f = document.forms["myForm"]
var s = 0
for (var i=1;i<=4;i++) {
var v = f.elements["Val"+i].value
v = parseFloat(v)
if (isNaN(v)) continue
v = Math.abs(v)
s+=v
}
f.elements["exptotal"].value = s
}
//-->
</SCRIPT>
</head>
<body>
<form name="myForm">
<p>
one: <input type=text name="Val1" onchange="sumIt()">
</p>
<p>
two: <input type=text name="Val2" onchange="sumIt()">
</p>
<p>
three: <input type=text name="Val3" onchange="sumIt()">
</p>
<p>
four; <input type=radio name="Val4" onchange="sumIt()">
</p>
<p>
Suma:<input type="text" READONLY class="disabled" name="exptotal" size="20"
value="0.00">
</p>
</form>
</body>
</html>
-------------