Something like this?
See: http://www.javascriptsource.com/form...heckboxes.html
Here's an updated version of the code...
Code:
<!DOCTYPE HTML>
<html>
<head>
<title> Checkbox Summation </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="costEntry">
<input type="checkbox" value="9.99" >Game 1 ( 9.99)<br>
<input type="checkbox" value="19.99">Game 2 (19.99)<br>
<input type="checkbox" value="27.50">Game 3 (27.50)<br>
<input type="checkbox" value="45.65">Game 4 (45.65)<br>
<input type="checkbox" value="87.20">Game 5 (87.20)
</div>
<input type="text" id="totalcost" value="">
<script type="text/javascript">
/* This script and many more are available free online at
The JavaScript Source!! http://www.javascriptsource.com
Created by: Jay Rumsey | http://www.nova.edu/~rumsey/ */
// Modified on: 2/22/2013
function UpdateCost() {
var sum = 0;
var sel = document.getElementById('costEntry').getElementsByTagName('input');
for (i=0; i<sel.length; i++) {
if (sel[i].checked == true) { sum += Number(sel[i].value); }
} document.getElementById('totalcost').value = sum.toFixed(2);
}
window.onload = function() {
var sel = document.getElementById('costEntry').getElementsByTagName('input');
for (var i=0; i<sel.length; i++) {
sel[i].onclick = function () { UpdateCost(); }
}
}
</script>
</body>
</html>
Bookmarks