2
Unable to click the label to select the check box with Bootstrap check box
source link: https://www.codesd.com/item/unable-to-click-the-label-to-select-the-check-box-with-bootstrap-check-box.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Unable to click the label to select the check box with Bootstrap check box
advertisements
So I have the following code:
// the loop
$countId = 0;
$dateOnce = '';
foreach ($postDates as $post):
if (substr($post->post_date, 0, 7) != $dateOnce) {
echo'
<div class="checkbox">
<label for="filterByPostDate-' . $countId . '">
<input type="checkbox" id="filterByPostDate-' . substr($post->post_date, 0, 7) . '" class="postDateFilters postDateFilterCb-' . $countId . '" name="filterByPostDate-' . $countId . '" value="' . substr($post->post_date, 0, 7) . '" '; if (isset($_SESSION["filterByPostDate"])) { $key = array_search(substr($post->post_date, 0, 7), $_SESSION["filterByPostDate"]); } else { $key = false; } if($key !== false) { echo 'checked'; } echo ' />
' . date('M, Y', strtotime($post->date_part)) . '
</label>
</div>
';
}
$dateOnce = substr($post->post_date, 0, 7);
$countId++;
endforeach;
// END the loop
Which outputs checkboxes and labels for the wordpress frontend. But when I click on the label for each checkbox the checkbox doesn't get selected.
Here is a js fiddle which shows the problem.
Cheers for the help.
you must include the id
of your element in <label for="">
<div class="checkbox">
<label for="filterByPostDate-2011-12">
<input type="checkbox" id="filterByPostDate-2011-12" class="postDateFilters postDateFilterCb-0" name="filterByPostDate-0" value="2011-12" />
Dec, 2011
</label>
</div>
<div class="checkbox">
<label for="filterByPostDate-2012-01">
<input type="checkbox" id="filterByPostDate-2012-01" class="postDateFilters postDateFilterCb-6" name="filterByPostDate-6" value="2012-01" />
Jan, 2012
</label>
</div>
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK