Jump to content

calculating checkboxes


Nat

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.