<label><input type="checkbox" data-price="5" /> Книжки</label><br />
<label><input type="checkbox" data-price="3" /> Сумка</label><br />
<label><input type="checkbox" data-price="10" checked /> Ручка</label><br />
<label><input type="checkbox" data-price="13" /> Карандаш</label><br />
<label><input type="checkbox" data-price="27" /> Что-то</label><br />
<div id="total">0 руб.</div>
<script>
var total = 0,
totalDiv = document.getElementById( 'total' ),
els = document.getElementsByTagName( 'input' );
for( var i = 0, el; el = els[ i++ ]; ) {
if ( el.type == "checkbox" && el.getAttribute( 'data-price' ) ) {
total += el.checked ? ( parseFloat( el.getAttribute( 'data-price' ) ) || 0 ) : 0;
el.onclick = function( e ) {
var target = e && e.target || window.srcElement;
total = target.checked ?
total + ( parseFloat( target.getAttribute( 'data-price' ) ) || 0 ) :
total - ( parseFloat( target.getAttribute( 'data-price' ) ) || 0 );
totalDiv.innerHTML = total + " руб.";
}
}
}
totalDiv.innerHTML = total + " руб.";
</script>