Nat Posted April 16, 2007 Share Posted April 16, 2007 hi! Was wondering if anyone could help me with this problem. I have made a form consisting of an array of seven checkboxes. I'm trying to figure out how to write a php script to calculate 1 dollar for every checkbox chosen. Nat. Link to comment https://forums.phpfreaks.com/topic/47194-calculating-checkboxes/ Share on other sites More sharing options...
Hughesy1986 Posted April 16, 2007 Share Posted April 16, 2007 Have you got any code you can show us? Glen Link to comment https://forums.phpfreaks.com/topic/47194-calculating-checkboxes/#findComment-230144 Share on other sites More sharing options...
HeyRay2 Posted April 16, 2007 Share Posted April 16, 2007 As Hughesy1986 suggested, seeing some of your code would be helpful, but for now let's assume you have a form looking somewhat like this: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="checkbox" name="checkboxes[]" value="CheckBox 1"> <input type="checkbox" name="checkboxes[]" value="CheckBox 2"> <input type="checkbox" name="checkboxes[]" value="CheckBox 3"> <input type="checkbox" name="checkboxes[]" value="CheckBox 4"> <input type="checkbox" name="checkboxes[]" value="CheckBox 5"> <input type="checkbox" name="checkboxes[]" value="CheckBox 6"> <input type="checkbox" name="checkboxes[]" value="CheckBox 7"> <input type="submit" name="submit" value="Submit!"> </form> You could check how many checkboxes were checked simply by doing something like this: <?php if($_POST['submit']){ $boxes_checked = count($_POST['checkboxes']); echo 'You clicked '.$boxes_checked.' box(es). You get $'.$boxes_checked.'!'; } ?> Link to comment https://forums.phpfreaks.com/topic/47194-calculating-checkboxes/#findComment-230159 Share on other sites More sharing options...
Nat Posted April 16, 2007 Author Share Posted April 16, 2007 Thank you so much 'HeyRay2'. You're a legend. You've solved my problem. Link to comment https://forums.phpfreaks.com/topic/47194-calculating-checkboxes/#findComment-230168 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.