adding labels to radio buttons

Mathemats

I am building a questionnaire and I have a label for the question and then radio buttons for the user to answer with. The question text is added with a label and then depending on the number of responses (yes/no/unsure, male/female) labelled radio buttons are added. My problem is that I am also trying to maintain accessibility and I need to have the question text label be associated with the radio buttons.

The label with the nested input(radio) associates fine, the one with issues is the one attached to the fieldset.

I am using the WAVE toolbar for basic compliance to accessibility standards, but I can't seem to get over the orphaned label errors.

<div>
    <label for="{{question.UniqueID}}" compile="question.Text"></label>
</div>
<div>
    <fieldset class="col-sm-6" id="{{question.UniqueID}}">
        <label class="radio-inline" ng-repeat="responseOption in question.Responses">
            <input type="radio"
                   name="{{question.QuestionID}}"
                   id="{{responseOption.UniqueID}}"
                   value="{{responseOption.ResponseOptionID}}"
                   ng-model="$parent.selectedOptionID"
                   ng-click="newValue(value, question, responseOption)">
            {{responseOption.Text}} <!--Male/Female, yes/no/unsure-->
        </label>
    </fieldset>
stringy

What you want is a legend in the fieldset, not a label. Labels are really only used to pair with inputs, hence the for/id suggestion in feitla's answer. Legends are the way to give an associated name to a fieldset. They're difficult to style though. You might be better off using the name attribute on the radio inputs to make them a group. Then you can just use a paragraph to put the question in instead. E.g.

<p>Q1: Do you like snozzberries?</p>
<input type=radio name=q1 id=q1-y /><label for=q1-y>Yes</label>
<input type=radio name=q1 id=q1-n /><label for=q1-n>No</label>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Labels for radio buttons in rails form

Accessibility and radio buttons without labels

How to align radio buttons and labels?

Adding custom radio buttons in android

Adding Radio Buttons on a MessageBox/DialogBox

Adding hovering color to radio buttons

Unable to align radio buttons and their labels in one line

How to align radio buttons horizontally below labels

Radio buttons without round circles but rectangle labels

Labels and Radio Buttons slightly misaligned, how to fix?

Correcting the position of modified checkbox and radio buttons and labels

Javascript adding radio buttons to dialog in DOM

Adding radio buttons dynamically to a div using jquery

Bootstrap radio buttons - adding variables with jquery

Excel VBA - dynamically adding radio buttons

radio buttons appearing without labels in table column using jQuery

How to set form labels for radio buttons in Laravel 7

CSS: How to add borders of different colors to input radio buttons labels?

How to prevent radio buttons being selected by clicking their labels

How do I use labels for a set of dynamically created radio buttons?

How can we change the color of radio buttons (and labels) for AppScipt?

Adding group of radio buttons on a form when a check box is checked

Display 5 stars for adding ratings instead of radio buttons

Adding two horizontally aligned radio buttons inside a group widget

Adding a class to collection_radio_buttons [Ruby on Rails]

Vanilla JS selectors help for adding values from a set of radio buttons

Adding radio buttons in Devise's new registration form

mvc: Adding values of radio buttons checked into a collection and saving to database

Adding a custom class to Radio Buttons in ASP.NET MVC 4