Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantically Correct HTML Checkbox lists

I've got an HTML checkbox list that I would like to display in the following format:

Click all that apply:
                                 Title A      Title B

Option 1                         [  ]         [  ]
Option 2                         [  ]         [  ]
Option 3                         [  ]         [  ]

I'm wondering what the best way to code this semantically?

I've seen a related question on semantically correct checkboxes, but this doesn't take into account the titles.

Any ideas?

like image 505
Sniffer Avatar asked Oct 22 '09 15:10

Sniffer


People also ask

What is the correct HTML for checkbox?

The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices.

What is semantically correct HTML?

Semantic HTML is the correct use of HTML to reinforce the meaning of content on a web page, rather than merely define its appearance. Semantically correct HTML helps search engines, screen readers, and other user devices determine the significance and context of web content.

How do you make a checkbox list in HTML?

The simplest way to create a checkbox in HTML is by using the input tag. We have set the input type to “checkbox” as you can see in the example code. The name attribute lets us give a name to the checkbox, and with the value attribute, we specify the value it holds.

How do I select one checkbox from multiple checkboxes in HTML?

change(function() { $("#myform input:checkbox"). attr("checked", false); $(this). attr("checked", true); }); This should work for any number of checkboxes in the form.


2 Answers

Labelled rows and columns? This is almost certainly a case where a table is the correct thing.

Imagine that, once the user has made their selections and submitted the form, you then display their choices back to them. It would clearly be correct to use a table to display the gathered data, so it is correct to use a table to display the form that gathers the data.

like image 106
NickFitz Avatar answered Sep 25 '22 19:09

NickFitz


I will suggest that a table would be the correct semantic structure for this because the meaning of a check box is determined by the row and column in which it appears.

Think of how you would display this set of 1s and 0s: You would do it in a table. All you are doing is making the cells editable.

I am even more convinced than when I started composing this post. A table is the right structure for this.

like image 35
Sinan Ünür Avatar answered Sep 24 '22 19:09

Sinan Ünür