<div id="container">
<input type="checkbox" name="price-input" value="10" onClick="calculate(this);" />10<br />
<input type="checkbox" name="price-input" value="20" onClick="calculate(this);" />20 <br />
<input type="checkbox" name="price-input" value="30" onClick="calculate(this);" />30 <br />
<input type="checkbox" name="price-input" value="40" onClick="calculate(this);" />40 <br />
</div>
Sum : <span id="sum">0</span>
var total = 0;
function calculate(item) {
if(item.checked){
total+= parseInt(item.value);
} else {
total-= parseInt(item.value);
}
document.getElementById('sum').innerHTML = total;
}