AE117 Posted December 29, 2010 Share Posted December 29, 2010 I have this. <input name="delete[]" type="checkbox" id="delete" value="1" /> What I want to is get the value from this which is the "1" AND Get the id which would be "delete" I can get the value but i cant seem to get the id This is what I have been using foreach($_REQUEST['delete'] as $index=>$val){ echo $index; echo $val; } echo $index just gives me the num of array I am on and the $val gives the actually value. Can anyone help me out with getting the id or how I can specify a id. THanks Quote Link to comment https://forums.phpfreaks.com/topic/222952-php-checkbox-array/ Share on other sites More sharing options...
PHPTOM Posted December 29, 2010 Share Posted December 29, 2010 Id is not passed to PHP. It is used client side in JS/CSS. Quote Link to comment https://forums.phpfreaks.com/topic/222952-php-checkbox-array/#findComment-1152783 Share on other sites More sharing options...
AE117 Posted December 29, 2010 Author Share Posted December 29, 2010 Is there a way around this so I can get both the value and a id that I state? Quote Link to comment https://forums.phpfreaks.com/topic/222952-php-checkbox-array/#findComment-1152787 Share on other sites More sharing options...
PHPTOM Posted December 29, 2010 Share Posted December 29, 2010 Couple of ideas: Use AJAX to submit the form to include both of them in a get statement Or: As the value put something like value="1&delete" Then you can explode it to form an array Eg: <input name="delete[]" type="checkbox" value="1&delete" /> $array = explode("&", $val); echo $array[0]; //Value echo array[1]; //ID Hope you get the jist Quote Link to comment https://forums.phpfreaks.com/topic/222952-php-checkbox-array/#findComment-1152793 Share on other sites More sharing options...
BlueSkyIS Posted December 29, 2010 Share Posted December 29, 2010 name each checkbox with the same name, set the value = to the id. then just delete the id's that are checked. <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { print_r($_POST['delete']); } ?> <html> <body> <form method='post' action=''> <input type='checkbox' name='delete[]' value='22'> <input type='checkbox' name='delete[]' value='44'> <input type='checkbox' name='delete[]' value='777'> <input type='checkbox' name='delete[]' value='your mom'> <input type='submit'> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/222952-php-checkbox-array/#findComment-1152801 Share on other sites More sharing options...
AE117 Posted December 30, 2010 Author Share Posted December 30, 2010 Figured it out HTML: <textarea name="description[<?php echo "2"; ?>]" id="description[]" cols="" rows="" style="width:300px;">Content Here</textarea> PHP: foreach ($_REQUEST['description'] as $key=>$checkbox) { echo $key; echo "<br />"; echo $checkbox; } Quote Link to comment https://forums.phpfreaks.com/topic/222952-php-checkbox-array/#findComment-1152809 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.