Senza le lungaggini di jQuery....
P.S. Ho presupposto che questo comportamento debba essere valido per tutte le checkbox con class="chkOptions". Gestiscitelo di conseguenza...codice:<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Esempio</title> <script type="text/javascript"> function chbSum () { var oDisplay = document.querySelector("#totale"); oDisplay.innerHTML = parseFloat(oDisplay.innerHTML) + (this.checked ? parseFloat(this.value) : - parseFloat(this.value)); } window.onload = function () { Array.prototype.forEach.call(document.querySelectorAll(".chkOptions"), function (oChB) { if (oChB.checked) { this.innerHTML = parseFloat(this.innerHTML) + parseFloat(oChB.value); } oChB.onchange = chbSum; }, document.querySelector("#totale")); }; </script> </head> <body> <form name="tuoForm"> <div id="totale">200.50</div> <h3>Opzioni</h3> <input name="checkbox[1]" class="chkOptions" value="10.00" type="checkbox" id="1"> <input name="checkbox[2]" class="chkOptions" value="15.00" type="checkbox" id="2"> <input name="checkbox[3]" class="chkOptions" value="20.00" type="checkbox" id="3"> <input name="checkbox[4]" class="chkOptions" value="25.00" type="checkbox" id="4"> </form> </body> </html>![]()

Rispondi quotando