How to dynamically create checkboxes in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarega
    New Member
    • Oct 2008
    • 82

    #16
    by counting the elements in the array....
    Code:
    $x=array('a','b','c');
    for($i=0;$i<count($x);$i++) {
    echo "<input type='checkbox' id='chk[$i]' onclick=\"list_array($x[$i]\" />$x[$i]<br>";
    }

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #17
      then your loop should look something like that.....
      Code:
      $x=array('a','b','c');
      for($i=0;$i<count($x);$i++) {
          echo "<input type='checkbox' id='chk[$i]' name='chk[$i]' value='$x[$i]' />$x[$i]<br>";
       }

      Comment

      Working...