faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

94 of 101 people (93%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I know which check boxes have been clicked from any number of boxes.

Jul 15th, 2000 07:02
Rini Setiadarma, Chirag Mehta, Ben Udall,


Here's an example :
<INPUT type=checkbox name="choice[]" value="one">One
<INPUT type=checkbox name="choice[]" value="two">Two
<INPUT type=checkbox name="choice[]" value="three">Three
<INPUT type=checkbox name="choice[]" value="four">Four
If the first and the third checkboxes have been clicked, you will have
an array variable $choice which contains :
$choice[0] = "one"
$choice[1] = "three"
Then you can process it as usual, e.g. :
   for($i=0; $i<count($choice); $i++) echo $choice[$i];
Remember to give all checkboxes a same name with '[]' behind it.