Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerate list of checkboxes and iterate through array of them in php/js
    text
    copied!<p>Ok, I am pretty stumped, looking in this code for more than 3 hours.</p> <p>I generate array of check boxes, like this:</p> <pre><code>&lt;?php while($row=mysql_fetch_array($result)){ // here generate some more html... echo '&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name ="ordered" onchange="checked()"/&gt;&lt;/td&gt;&lt;/tr&gt;' echo "&lt;/table&gt;"; ?&gt; </code></pre> <p>I have two js functions like this:</p> <pre><code>&lt;head&gt; &lt;script&gt; function removeDuplicateElement(arrayName){ var newArray=new Array(); label:for(var i=0; i&lt;arrayName.length;i++ ){ for(var j=0; j&lt;newArray.length;j++ ){ if(newArray[j]==arrayName[i]) continue label; } newArray[newArray.length] = arrayName[i]; } return newArray; } var array = new Array(); function checked(){ var chkOrd = document.myForm.ordered; for (i=0; i &lt; chkOrd.length; i++){ if(chkOrd.checked){ array.push(chkOrd[i]); //document.myForm.hid.value =chkOrd[i].value; document.myForm.hid.value += removeDuplicateElement(array); //alert("kliknuto je na " + array[1]); } } } &lt;/script&gt; &lt;/head&gt; </code></pre> <p>and when i post infos to php with this:</p> <pre><code>$hid = $_POST['hid']; echo $hid; </code></pre> <p>I always get empty array, like no checkboxes is passed to php. I know that php sends on only checked checkboxes, but my array is empty even if there are checked boxes... I think that there are some problem with generated checkboxes, because i cannot even get single item of checked boxes array.</p> <p>Thank you in advance...</p>
 

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