<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </head> <body> <input type="checkbox" name="three" value="" /> -3 <input type="checkbox" name="eight" value="" /> - 8 <input type="sumbit" /> <script type="text/javascript"> Что собственно тут создать? каким макаром через value? </script> </body> </html>
<script src="http://code.jquery.com/jquery-latest.min.js"></script> <input type="checkbox" name="three" value="3" /> <input type="checkbox" name="eight" value="8" /> <input type="submit" /> <script> $(function () { $('body').bind('click', function (e) { if (e.target.type == 'checkbox') { var num = 0; $(':checked').each(function () { num += parseInt(this.value); }); alert(num); } }); }); </script>
var e = e || event; var target = e.target || e.srcElement;
<script src="http://code.jquery.com/jquery-latest.min.js"></script> <input type="checkbox" name="three" value="3" /> <input type="checkbox" name="eight" value="8" /> <input type="submit" /> <script> var body = $( 'body' ); var inputs = body.find( 'input:checkbox' ); body.on( 'click', ':checked', function() { var sum = 0; if ( inputs.filter( ':checked' ).length === 2 ) { inputs.each( function() { sum += +this.value; }); alert( sum ); } }); </script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </head> <body> <form id='input'> <input type="checkbox" name="three" value="-3" /> -3 <input type="checkbox" name="eight" value="-8" /> -8 <input id="res" type="sumbit" /> </form> <script type="text/javascript"> var input = document.getElementById('input'); var res = document.getElementById('res'); var sum = 0; input.onclick = function(e) { e = e || window.event; var target = e.target || e.srcElement; while(target != input) { if (target.nodeName == 'INPUT') { if(target.checked){ sum += parseInt(target.value); res.value = sum; return; } target = target.parentNode; } } } </script> </body> </html>