0

I have the following HTML code:

<table border = 0 cellpadding=5 >

<tr>
<td><input type="checkbox" name="all_sizes" value="All">All<br></td>
<td><input type="checkbox" name="10mm" value="10mm">10mm<br></td>
<td><input type="checkbox" name="20mm" value="20mm">20mm<br></td>
<td><input type="checkbox" name="30mm" value="30mm">30mm<br></td>
<td><input type="checkbox" name="40mm" value="40mm">40mm<br></td>
</tr>
</table>

How would we go about selecting the first check box by default?

4
  • 3
    Add checked = "checked" to the input you want selected. Commented Nov 17, 2012 at 5:36
  • i think its just the keyword checked Commented Nov 17, 2012 at 5:42
  • 1
    For XHTML the recommended way is as described. Check HTML manual and W3C to confirm. Commented Nov 17, 2012 at 5:45
  • 1
    The markup posted isn’t XHTML, so it’s logical to use just the simple keyword attribute checked. Commented Nov 17, 2012 at 9:19

2 Answers 2

11

Change this:

<td><input type="checkbox" name="all_sizes" value="All">All<br></td>

to this (add the keyword 'checked'):

<td><input type="checkbox" name="all_sizes" value="All" checked>All<br></td>
Sign up to request clarification or add additional context in comments.

Comments

5

Assuming that you've fetched your data from mysql using mysqli_query()

<td><input type="checkbox" name="all_sizes" value="All" <?php if($data['col_name'] == 'val') { echo 'checked'; }?>>Value</td>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.