php - Count checked checkboxes -


i new html, have list of checkboxes on form in html page.

each checkbox on each line represents different category "i" "d" "c" , "s".

part of code follows:

<form>     1.<input type="checkbox" name="personality_1.1" value="i"/>animated &nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_1.2" value="d" />adventurous &nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_1.3" value="c" />analytical &nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_1.4" value="s" />adaptable<br /><br />      2.<input type="checkbox" name="personality_2.1" value="i"/>playful&nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_2.2" value="d" />persuasive&nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_2.3" value="c" />persistent&nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_2.4" value="s" />peaceful<br /><br />      3.<input type="checkbox" name="personality_3.1" value="i"/>sociable&nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_3.2" value="d" />strong willed&nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_3.3" value="c" />self-sacraficing&nbsp;&nbsp;&nbsp;&nbsp     <input type="checkbox" name="personality_3.4" value="s" />submissive<br /><br /> 

i need find out how many value "i" checkboxes have been checked, how many value "d" checkboxes have been checked, , on, , display total of each category when form submitted.

such a: "five d's have been checked" "three c's have been checked"

is there way can javascript or php? if can direct me figure out how so?

well, php, assuming submitting form post:

$counts = array_count_values($_post); 

and you'll associative array values keys , counts values. if example 3 d's have been checked, $counts['d'] hold "3".


Comments