Reputation: 372
I am dynamically creating the checkbox input fields with text lables, and trying to create a treeview when I click any item in the tree the first check box is always toggling.What can be the possible reason.
if($category->visible==1){
echo '<div class="categorylist level'.$depth.' cat">';
$count=$DB->count_records('course',['category'=>$category->id]);
if($count>0){
echo '<div class="parent">';
if($depth>0){
$indent=10;
for($i=0;$i<=$depth;$i++){
$indent=$indent+$depth;
echo '<div style="margin-left:'.$indent.'px">';
}
}
echo '<input type="checkbox" id="category" name="cat[]" value='.$category->id.'/>';
echo '<label for="category"'.$category->id.'"><span class="">'.$category->name.' ('.$count.')</span></label><br>';
if($depth>0){
for($i=0;$i<=$depth;$i++){
echo '</div>';
}
}
echo '</div>';
}
else{
echo '<div class="parent">';
if($depth>0){
$indent=10;
for($i=0;$i<=$depth;$i++){
$indent=$indent+$depth;
echo '<div style="margin-left:'.$indent.'px">';
}
}
echo '<label for="category"><span class="">'.$category->name.' ('.$count.')</span></label><br>';
if($depth>0){
for($i=0;$i<=$depth;$i++){
echo '</div>';
}
}
echo '</div>';
}
echo '</div>';
}
Upvotes: 0
Views: 41
Reputation: 11622
Just checked this <label for="category"'.$category->id.'">
could be your issue, label with duplicate for
attribute can cause this issue, make sure that you have no label with same $category->id
Upvotes: 1