Jump to content

calculating checkboxes


Nat

Recommended Posts

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.'!';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.