Form calculator

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>

-------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,077
Messages
2,570,569
Members
47,205
Latest member
KelleM857

Latest Threads

Top