0

How do you find out how many checkboxes have been checked for given Question? For example, you have question called "Hobbies:"with checkbox options of Reading, Biking, Travelling., I want get the count of the hobbies.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by v srinivasa rao
0

Assuming you are using PHP to process your form, when you create your form
give all your checkboxes the same name BUT add the following suffix "[]" -ex:

<form method="post" ...>
<input type="checkbox" name="hobbies[]" value="Reading"/>
<input type="checkbox" name="hobbies[]" value="Biking"/>
<input type="checkbox" name="hobbies[]" value="Traveling"/>
...
</form>

Then when you submit your form then:

if( isset($_POST['hobbies']) )
  echo 'Total Hobbies: '.count($_POST['hobbies']);
else
  echo 'No Hobbies checked';
0

<form method="post" ...>
<input type="checkbox" name="hobbies[]" value="Reading"/>
<input type="checkbox" name="hobbies[]" value="Biking"/>
<input type="checkbox" name="hobbies[]" value="Traveling"/>
...
</form>

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.