Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect order in which checkboxes are clicked
    primarykey
    data
    text
    <p>I am trying to make a page that allows users to select 8 checkboxes from a total of 25.</p> <p>Im wondering, <strong>how to detect the exact order in which they check them</strong>. I am using a plain html front page that will be verified by a form action pointing to a php page.</p> <p>Im trying to get a result like (checkbox1,checkbox2,checkbox6,checkbox3,checkbox7,etc) for eight checkboxes, and the exact order in which they were clicked.</p> <p>I think I have found what I am looking for,Im not too sure, but Im having trouble implementing it.</p> <p>This is what I have so far, I guess my question is, what type of php do I need to gather this info once a user has submitted the form.</p> <p>For the form I have:</p> <pre><code>&lt;form id="form1" name="form1" method="post" action="check_combination.php"&gt; &lt;label id="lblA1"&gt;&lt;/label&gt; &lt;input name="checkbox1" type="checkbox" value="a1" onclick="setChecks(this)"/&gt; Option 1 &lt;label id="lblA2"&gt;&lt;/label&gt; &lt;input name="checkbox1" type="checkbox" value="a2" onclick="setChecks(this)"/&gt; Option 2 &lt;label id="lblA3"&gt;&lt;/label&gt; &lt;input name="checkbox1" type="checkbox" value="a3" onclick="setChecks(this)"/&gt; Option 3 &lt;label id="lblA4"&gt;&lt;/label&gt; &lt;input name="checkbox1" type="checkbox" value="a4" onclick="setChecks(this)"/&gt; Option 4 &lt;/form&gt; </code></pre> <p>For the Javascript I have:</p> <pre><code>&lt;script type="text/javascript"&gt; &lt;!-- //initial checkCount of zero var checkCount=0 //maximum number of allowed checked boxes var maxChecks=8 function setChecks(obj){ //increment/decrement checkCount if(obj.checked){ checkCount=checkCount+1 }else{ checkCount=checkCount-1 } //if they checked a 4th box, uncheck the box, then decrement checkcount and pop alert if (checkCount&gt;maxChecks){ obj.checked=false checkCount=checkCount-1 alert('you may only choose up to '+maxChecks+' options') } } //--&gt; &lt;/script&gt; &lt;script type="text/javascript"&gt; &lt;!-- $(document).ready(function () { var array = []; $('input[name="checkbox1"]').click(function () { if ($(this).attr('checked')) { // Add the new element if checked: array.push($(this).attr('value')); } else { // Remove the element if unchecked: for (var i = 0; i &lt; array.length; i++) { if (array[i] == $(this).attr('value')) { array.splice(i, 1); } } } // Clear all labels: $("label").each(function (i, elem) { $(elem).html(""); }); // Check the array and update labels. for (var i = 0; i &lt; array.length; i++) { if (i == 0) { $("#lbl" + array[i].toUpperCase()).html("first"); } if (i == 1) { $("#lbl" + array[i].toUpperCase()).html("second"); } } }); }); //--&gt; &lt;/script&gt; </code></pre> <p>I have gotten the part that only allows 8 checkboxes to be checked, but Im stuck as to what I need to do to actually parse the data once it has been submitted to a page with a name like check_combination.php.</p> <p>I would appreciate any help</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