kks_krishna Posted July 13, 2007 Share Posted July 13, 2007 HI, How to get the values when I am using the checkbox names filed without [].Its not workingf without using labels[]. But i dont want to use array symbol since its giving problem in JavaScript. <input type="checkbox" name="labels" value="spring">Spring <input type="checkbox" name="labels" value="hibernate">Hibernate <input type="checkbox" name="labels" value="seam">JBoss Seam <input type="checkbox" name="labels" value="javafx">JavaFX <input type="checkbox" name="labels" value="jsf">JSF <input type="checkbox" name="labels" value="struts">Struts<br> Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/ Share on other sites More sharing options...
jitesh Posted July 13, 2007 Share Posted July 13, 2007 <form> <input type="hidden" name="totcheckbox" value="6"> <input type="checkbox" name="labels0" value="spring">Spring <input type="checkbox" name="labels1" value="hibernate">Hibernate <input type="checkbox" name="labels2" value="seam">JBoss Seam <input type="checkbox" name="labels3" value="javafx">JavaFX <input type="checkbox" name="labels4" value="jsf">JSF <input type="checkbox" name="labels5" value="struts">Struts<br> </form> when post for($i=0;$i<$_POST['totcheckbox'];$i++){ if(isset($_POST['labels'.$i])){ } } Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297329 Share on other sites More sharing options...
Jewbilee Posted July 13, 2007 Share Posted July 13, 2007 or: <input type="checkbox" name="labels[]" value="struts">BLAH $labels = $_POST['labels']; foreach($labels as $key => $value) { //do stuff } use the name labels[] from each one, theyll all be stored in the array. Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297337 Share on other sites More sharing options...
kks_krishna Posted July 13, 2007 Author Share Posted July 13, 2007 <form> <input type="hidden" name="totcheckbox" value="6"> <input type="checkbox" name="labels0" value="spring">Spring <input type="checkbox" name="labels1" value="hibernate">Hibernate <input type="checkbox" name="labels2" value="seam">JBoss Seam <input type="checkbox" name="labels3" value="javafx">JavaFX <input type="checkbox" name="labels4" value="jsf">JSF <input type="checkbox" name="labels5" value="struts">Struts </form> when post for($i=0;$i<$_POST['totcheckbox'];$i++){ if(isset($_POST['labels'.$i])){ } Thats great. Now I want pass it as array to other method. bcos that method already takes only array. How can i set all the values into single array? Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297338 Share on other sites More sharing options...
Jewbilee Posted July 13, 2007 Share Posted July 13, 2007 yea, if you want to pass it as an array, use my method, when you pull it from $_POST, it already is one. Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297340 Share on other sites More sharing options...
kks_krishna Posted July 13, 2007 Author Share Posted July 13, 2007 yea, if you want to pass it as an array, use my method, when you pull it from $_POST, it already is one. The problem is i cannot use "labels[]" in html. so i need some workaround to complete it. without using[] Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297342 Share on other sites More sharing options...
Jewbilee Posted July 13, 2007 Share Posted July 13, 2007 edit: didnt see your problem at the top, my bad. in that case; do what the other person suggested, but once you've verified whether or not the checkbox is set, add it to an array $labels[] from the for loop. Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297345 Share on other sites More sharing options...
jitesh Posted July 13, 2007 Share Posted July 13, 2007 when post to next page $set_checked_labels_array = array(); for($i=0;$i<$_POST['totcheckbox'];$i++){ if(isset($_POST['labels'.$i])){ $set_checked_labels_array[] = $_POST['labels'.$i]; } } echo " < pre> "; echo "checked labels"; print_r($set_checked_labels_array); Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297348 Share on other sites More sharing options...
kks_krishna Posted July 13, 2007 Author Share Posted July 13, 2007 Ya..its working. But now i am facing problem in JavaScript. I will solve it. Link to comment https://forums.phpfreaks.com/topic/59802-help-needed-for-checkbox/#findComment-297351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.