I’m creating a form that has two checkboxes yes and no. I have added a yes or no into a mysql field called Completed.
The problem I have is getting the tick boxes to show a tick if the field that has a Yes or a No.
So depending what is in the field Completed “Yes” or “No” the tick boxes should be ticked or not ticked.
My code is like this:
<input type="checkbox" name="Completed" Completed="Yes" value="<?php echo $stuff["Completed"]; ?>" <?php echo $stuff["Completed"] ? 'checked=" checked"' : ''; ?> > Yes</td>
<input type="checkbox" name="Completed" Completed="No" value="<?php echo $stuff["Completed"]; ?>" <?php echo $stuff["Completed"] ? 'checked=" checked"' : ''; ?> > No</td>
Check boxes don’t strike me as an appropriate control for this type of information. Have you considered using radio buttons instead? In any case, the answer to your question depends on how you are storing the data in the database. If it is a simple “Yes” or “No”, then try something like the following: