Page 1 of 1
Multiple check boxs
Posted: Mon Oct 13, 2008 5:56 pm
by petethepirate
I cant figure this one out. I need mutiple check boxes (form submit) for each item, not just one check box. For example, lets say I list out fruit items at a grocery store. For each item I have a check box for BUY, INSPECT, and SMELL. I can check one, two, all three, or none at all. Anyone know how to do this? Thanks.
Re: Multiple check boxs
Posted: Mon Oct 13, 2008 6:38 pm
by califdon
petethepirate wrote:I cant figure this one out. I need mutiple check boxes (form submit) for each item, not just one check box. For example, lets say I list out fruit items at a grocery store. For each item I have a check box for BUY, INSPECT, and SMELL. I can check one, two, all three, or none at all. Anyone know how to do this? Thanks.
Unless I don't understand what you want to do, just give each checkbox a different name. What are you doing with the data?
Re: Multiple check boxs
Posted: Mon Oct 13, 2008 6:48 pm
by petethepirate
I am giving them different names. Lets say someone clicks two different check boxs on line 2, all it returns is ON for line 2. Im trying to get 3 different values from each line.
Re: Multiple check boxs
Posted: Mon Oct 13, 2008 7:21 pm
by califdon
petethepirate wrote:I am giving them different names. Lets say someone clicks two different check boxs on line 2, all it returns is ON for line 2. Im trying to get 3 different values from each line.
I can't visualize what you mean. Show us the code for your Form (please enclose php code in bracketed php tags for readability--that is, use the Code button on the message input screen, and change the "text" to "php" if it's php code).
Re: Multiple check boxs
Posted: Mon Oct 13, 2008 8:21 pm
by omika
So its like
Apple: []Buy
[]Inspect
[]Smell
Pear: []Buy
[]Inspect
[]Smell
Code: Select all
<?php
echo "Apple: <input type='checkbox' name='apple[]' value='Buy'>Buy<br>
<input type='checkbox' name='apple[]' value='Inspect'>Inspect<br>
<input type='checkbox' name='apple[]' value='Smell'>Smell<br><br>";
echo "Pear: <input type='checkbox' name='pear[]' value='Buy'>Buy<br>
<input type='checkbox' name='pear[]' value='Inspect'>Inspect<br>
<input type='checkbox' name='pear[]' value='Smell'>Smell<br><br>";
?>
Lets say Apple has buy and smell selected, an array called apple now contains Buy and Smell. When you post you can do whatever with the array eg.
Code: Select all
<?php
$applestuff = implode(', ', $_POST['apple']); //Converts an array into a single string
echo $applestuff; //Output: Buy, Smell
?>
Re: Multiple check boxs
Posted: Mon Oct 13, 2008 8:21 pm
by petethepirate
Thanks!