Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect All Checkbox
    primarykey
    data
    text
    <p>I have a webpage that returns search results in a table/form. I would like to have a select all checkbox, that would select all the checkboxes for the search results. My code for the display results is below:</p> <pre><code>&lt;form action="noJavaScript.php" name="theForm" method="post"&gt; &lt;table style="border: 1px solid black" RULES=ALL FRAME=VSIDES&gt; &lt;th&gt; &lt;/th&gt;&lt;th&gt;Order #&lt;/th&gt;&lt;th&gt;Inspector&lt;/th&gt;&lt;th&gt;Reference #&lt;/th&gt;&lt;th&gt;Client Name&lt;/th&gt;&lt;th&gt;Property Address&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;&lt;th&gt;State&lt;/th&gt;&lt;th&gt;Zip&lt;/th&gt;&lt;th&gt;Inspection Date&lt;/th&gt; &lt;?php while ($row = mysql_fetch_assoc($result)) { echo '&lt;tr&gt;&lt;td&gt;'; echo '&lt;input type="checkbox" name="selected[]" value="'.$row['order_number'].'"/&gt;'; echo '&lt;/td&gt;'; foreach ($row as $key =&gt; $value) echo '&lt;td&gt;'.htmlspecialchars($value).'&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; &lt;/table&gt; &lt;input type="submit" name="submit" value="Edit/Modify Order" onClick="document.theForm.action='modify.php'"&gt; &lt;input type="submit" name="submit" value="Clone Order" onClick="document.theForm.action='clone.php'"&gt; &lt;input type="submit" name="submit" value="Delete Order" onClick="document.theForm.action='deleteorder.php'"&gt; &lt;input type="submit" name="submit" value="Archive Order" onClick="document.theForm.action='archive.php'"&gt; &lt;/form&gt; </code></pre> <p>I have tried using the following function:</p> <pre><code>&lt;script type="text/javascript" &lt;!-- function SetAllCheckBoxes(FormName, FieldName, CheckValue) { if(!document.forms[FormName]) return; var objCheckBoxes = document.forms[FormName].elements[FieldName]; if(!objCheckBoxes) return; var countCheckBoxes = objCheckBoxes.length; if(!countCheckBoxes) objCheckBoxes.checked = CheckValue; else // set the check value for all check boxes for(var i = 0; i &lt; countCheckBoxes; i++) objCheckBoxes[i].checked = CheckValue; } // --&gt; &lt;/script&gt; </code></pre> <p>And the button like this:</p> <pre><code> &lt;input type="button" onclick="SetAllCheckBoxes('theForm', 'myCheckbox', true);" value="Check All"&gt;; </code></pre> <p>But I can't get it to work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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