hi2you Posted February 29, 2008 Share Posted February 29, 2008 Hello, I have a list of check box <form name="form" action="test.php" method="POST"> <input type="checkbox" name="option1" value="a"> a<br> <input type="checkbox" name="option2" value="b" > b<br> <input type="checkbox" name="option3" value="c"> c<br> </form> and in test.php, I have a String varible $text, and if a and b are checked, then $text = "ab". if a, c are checked, then $text becomes "ac". How to do so?? Thanks!! Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 29, 2008 Share Posted February 29, 2008 try this, form page... <form name="form" action="test.php" method="POST"> <input type="checkbox" name="opt[]" value="a"> a <input type="checkbox" name="opt[]" value="b" > b <input type="checkbox" name="opt[]" value="c"> c <input type="submit" /> </form> test.php... <?php foreach($_POST['opt'] as $opt) $text .= $opt; echo $text; ?> Quote Link to comment Share on other sites More sharing options...
hi2you Posted February 29, 2008 Author Share Posted February 29, 2008 Thanks, I see how it works now, but what if the box is unchecked and I dont want the value of the unchecked into $text?? your example will String up all checked as well as the unchecked values right? Quote Link to comment Share on other sites More sharing options...
fooDigi Posted February 29, 2008 Share Posted February 29, 2008 it shouldn't, try it for me it worked Quote Link to comment Share on other sites More sharing options...
thebadbad Posted February 29, 2008 Share Posted February 29, 2008 or <form action="test.php" method="post"> <input type="checkbox" name="option1" value="a" /> a <input type="checkbox" name="option2" value="b" /> b <input type="checkbox" name="option3" value="c" /> c <input type="submit" /> </form> test.php <?php $text = ''; for ($i = 1; $i <= 3; $i++) { $text .= $_POST['option'.$i]; } ?> To answer your question, unchecked checkboxes won't get submitted at all. Quote Link to comment Share on other sites More sharing options...
hi2you Posted February 29, 2008 Author Share Posted February 29, 2008 Thanks guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.