Hi, Was hoping someone out there could help with this problem. I have creating a form with an array of 7 checkboxes. I am trying to write a script that will calculate a cost of $1 for every checkbox chosen. Please help!
Do you want it in php if yes then while checking each check box just submit the form and update it. This code may too some extend help you : Any more help needed always welcome
<html> <head></head> <!-- I am a free download : http://www.prototypejs.org/download --> <script language="javascript" src="prototype.js"></script> <!-- I am some simple prototype usage --> <script language="javascript"> function calculate( ) { var rets = 0; var data = $('mainform').getInputs( 'checkbox' ).toArray(); data.each( function(item) { if( item.checked ) { rets += parseInt( item.value ) } } ); $('result').innerHTML = 'Total : $' + rets + '<br />'; $('opt_value').value = rets; } </script> <body> <div id="result"></div> <form action="" method="post" name="mainform" id="mainform"> <input type="checkbox" name="opt[]" value="5" onclick="calculate( );"/><br /> <input type="checkbox" name="opt[]" value="1" onclick="calculate( );"/><br /> <input type="checkbox" name="opt[]" value="5" onclick="calculate( );"/><br /> <input type="checkbox" name="opt[]" value="1" onclick="calculate( );"/><br /> <input type="checkbox" name="opt[]" value="1" onclick="calculate( );"/><br /> <input type="checkbox" name="opt[]" value="1" onclick="calculate( );"/><br /> <input type="checkbox" name="opt[]" value="1" onclick="calculate( );"/><br /> <input type="checkbox" name="opt[]" value="1" onclick="calculate( );"/><br /> <!-- NO SUBMIT BUTTON NEEDED, SUM CALCULATED ON EACH CHANGE AND STORED IN opt_value --> <input type="hidden" name="opt_value" id="opt_value" value="" /> </form> </body> </html> HTML: Uses prototype.js link inside, also allows you to have different values assigned to every checkbox in an array......