I have the following piece of code that is used to set up checkboxes during initial page load:
for ($y = 0; $y < $itemcount; $y++) {
$yesno = (bool) $items[$y];
$checked = ($yesno) ? 'checked="checked" disabled="true" ': '';
echo '<td align="center">';
echo "<input type='checkbox' ". $checked . " onclick='chkcountfn($y,\"$rowid\") ' />";
echo'</td>';
}
Basically it loops through a string, $items, which is a string of numerics in the format “nnnnnnnnnnnnn”. This can be variable length which is reflected by $itemcount e.g. , “1020000574302”, and gets the number at each position.
If the number is non-zero then the associated checkbox should be checked and disabled.
However although the relevent checkboxes are disabled they are not checked.
I wondered if it was due to having the onclick event, but taking it out makes no difference.
When I check the browser developer tools inspector the line for one of disabled checkboxes shows:
<input type=“checkbox” checked=“checked” disabled=“true” onclick="chkcountfn(4,“row24”) ">
which I thought should work.
I use a very similar piece of code in another PHP file, and this checks the checkbox ok. However instead of echoing the line it uses HTML with inline PHP:
<?php $yesno = (bool) $hospchk; $hosp = ($yesno) ? 'checked="checked"' : ''; ?> <input type="checkbox" <?php echo $hosp; ?> />
Is there a reason why the PHP echo version isn’t working?