Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot retrieve the checkbox status
    primarykey
    data
    text
    <p>I have a table with some checkboxes in every row. There is a select element in the table footer with several options. When the user chooses an option, i want to pass the value of any checked checkboxes and the selected option to a php script.</p> <p>This is the form:</p> <pre><code>&lt;form name="doall" method="POST" action="action.php"&gt; &lt;table&gt; &lt;tbody&gt; &lt;?php for($j=0;$j&lt;count($userToRead);$j++){ ?&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" id="selection_&lt;?php echo $j ?&gt;" name="objectSelected[&lt;?php echo $userToRead[$j]['id'] ?&gt;]" value="1"/&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;?php echo $userToRead[$j]['id'] ?&gt; &lt;/td&gt; &lt;td align="center" style="text-align:center;padding-left:15px;background-color:&lt;?php echo $SListsStatus[intval($userToRead[$j]['userstatus'])][1]; ?&gt;;" &gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;?php echo stripaccenti($userToRead[$j]['user']) ?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo stripaccenti($SUserType[$userToRead[$j]['type']]['name']) ?&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;?php echo stripaccenti($userToRead[$j]['first_name']) ?&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;?php echo stripaccenti($userToRead[$j]['last_name']) ?&gt; &lt;/td&gt; &lt;td align="center"&gt; &lt;?php echo stripaccenti($userToRead[$j]['title']) ?&gt; &lt;/td&gt; &lt;td class="actBtns"&gt; &lt;a href="#" title="Update" class="tipS"&gt; &lt;img src="images/icons/edit.png" alt="" /&gt; &lt;/a&gt; &lt;a href="#" title="Remove" class="tipS"&gt; &lt;img src="images/icons/remove.png" alt="" /&gt; &lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } // end for ?&gt; &lt;/tbody&gt; &lt;tfoot&gt; &lt;tr&gt; &lt;td colspan="9"&gt; &lt;div class="itemActions"&gt; &lt;label&gt;Con tutte le selezionate:&lt;/label&gt; &lt;select name="whatDoAll"&gt; &lt;option value="1"&gt;Attiva&lt;/option&gt; &lt;option value="2"&gt;Disattiva&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" value="Esegui" class="button redB" style="margin: 5px;"/&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tfoot&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>So in every line of my table I have a checkbox where the value is the ID of the db object that I need to modify with my php script.</p> <p>This is my script:</p> <pre><code>$('input[type="submit"]').click(function() { var output = ''; $('input[type="objectSelected"]:checked').each(function(index) { output += $(this).val() + ", "; }); alert(output + "is checked!"); }); </code></pre> <p>In the php file i try to retrieve the variable with <code>$_POST['objectSelected']</code> but the variable is always empty. Also, the script alert is empty.</p> <p>The tables are create with jquery: <strong>if I use a pure html table with pure html checkboxes everything works!</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload