PDA

View Full Version : Good and Nice JavaScripts



JavaScriptBank
02-24-2011, 12:14 AM
Helpful JavaScript for Web development

Simple JavaScript for Auto-Sum with Checkboxes

This JavaScript code example uses a for loop to calculate the sum of JavaScript checkbox values (http://www.javascriptbank.com/=JavaScript checkbox value). This JavaScript will display a running total automatically wh... detail (http://www.javascriptbank.com/simple-javascript-auto-sum-with-checkboxes.html/en//) at JavaScriptBank.com - 2.000+ free JavaScript codes (http://www.javascriptbank.com/)


http://www.javascriptbank.com/javascript.images/form/simple-javascript-auto-sum-with-checkboxes.jpg (http://www.javascriptbank.com/javascript/form/checkbox-radio/simple-javascript-auto-sum-with-checkboxes/preview/en/)
Demo: JavaScript Simple JavaScript for Auto-Sum with Checkboxes (http://www.javascriptbank.com/simple-javascript-auto-sum-with-checkboxes.html/en/)


How to setup

Step 1: Use JavaScript code below to setup the script
JavaScript

<script type="text/javascript">
// Created by: Jay Rumsey | http://www.nova.edu/~rumsey/
// This script downloaded from JavaScriptBank.com

function UpdateCost() {
var sum = 0;
var gn, elem;
for (i=0; i<5; i++) {
gn = 'game'+i;
elem = document.getElementById(gn);
if (elem.checked == true) { sum += Number(elem.value); }
}
document.getElementById('totalcost').value = sum.toFixed(2);
}
</script>

Step 2: Copy & Paste HTML code below in your BODY section
HTML

<input type="checkbox" id='game0' value="9.99" onclick="UpdateCost()">Game 1 ( 9.99)<br>
<input type="checkbox" id='game1' value="19.99" onclick="UpdateCost()">Game 2 (19.99)<br>
<input type="checkbox" id='game2' value="27.50" onclick="UpdateCost()">Game 3 (27.50)<br>
<input type="checkbox" id='game3' value="45.65" onclick="UpdateCost()">Game 4 (45.65)<br>
<input type="checkbox" id='game4' value="87.20" onclick="UpdateCost()">Game 5 (87.20)<br>







AJAX news ticker (http://www.javascriptbank.com/rss-ajax-newsticker.html) - JavaScript Refresh Page (http://www.javascriptbank.com/refresh-page-automatic.html/en/) - JavaScript Unclosable Window (http://www.javascriptbank.com/blink.html)


The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.