xerox02 Posted May 3, 2010 Share Posted May 3, 2010 <html> <body> <form method="post" action="path to script"> <input type="checkbox" id="colors[]" value="red" /> Red <input type="checkbox" id="colors[]" value="blue" /> Blue <input type="checkbox" id="colors[]" value="green" /> Green <input type="checkbox" id="colors[]" value="yellow" /> Yellow </form> </form> </body> </html> <?php $colors=($_POST['colors']); echo "What color was chosen? =" . $colors; ?> I am trying make a variable that gets the values of check boxes, and then echoes them. Link to comment https://forums.phpfreaks.com/topic/200582-get-html-check-box-values-and-then-echo-values/ Share on other sites More sharing options...
abdfahim Posted May 3, 2010 Share Posted May 3, 2010 <html> <body> <form method="post" action=""> <input type="checkbox" name="colors[]" value="red" /> Red <input type="checkbox" name="colors[]" value="blue" /> Blue <input type="checkbox" name="colors[]" value="green" /> Green <input type="checkbox" name="colors[]" value="yellow" /> Yellow <input type="submit" value="Submit" name="col_sub"> </form> </body> </html> <?php if(isset($_POST['col_sub'])){ $colors=$_POST['colors']; echo "What color was chosen? ="; for($i=0;$i<count($colors);$i++){ echo $colors[$i]." "; } } ?> Link to comment https://forums.phpfreaks.com/topic/200582-get-html-check-box-values-and-then-echo-values/#findComment-1052534 Share on other sites More sharing options...
xerox02 Posted May 3, 2010 Author Share Posted May 3, 2010 Thanks a lot man If there a way I can get values without having a submit box? Also, is there a way where I could just have button I designed, and if I click the button it would be as if it were checked. After that I can echo the checked values into a variable Link to comment https://forums.phpfreaks.com/topic/200582-get-html-check-box-values-and-then-echo-values/#findComment-1052538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.