Radio Button Input: Type radio attribute & value attribute
HTML FORMS
Checkboxes work well if we want to present users with multiple options and let them choose one or more of the options. However, there are cases where we want to present multiple options and only allow for one selection — like asking users if they agree or disagree with the terms and conditions. Let’s look over the code used to create radio buttons:
<form>
<p>What is sum of 1 + 1?</p>
<input type="radio" id="two" name="answer" value="2">
<label for="two">2</label>
<br>
<input type="radio" id="eleven" name="answer" value="11">
<label for="eleven">11</label>
</form>
Which renders:

Notice from the code snippet, radio buttons (like checkboxes) do not display their value. We have an associated <label> to represent the value of the radio button. To group radio buttons together, we assign them the same name and only one radio button from that group can be selected.
Let’s see this in action by creating our own radio buttons.
Instructions:
1.We can give our users the option to make the burger into a cheeseburger. Let’s use radio buttons for that.
In <section> element with a class of "cheesy" there are two <label>s that don’t have associated <input> elements. Add an <input> element associated with the first <label>.
The created <input> should have:
- an
idset to"yes". - a
typeset to"radio". - a
nameattribute with a value of"cheese". - a
valueof"yes". - Hint:
- Assign the attributes and values inside the
<input>tag.
<input> element to give users another choice. The created <input> should have:- an
idset to"no". - a
typeset to"radio". - a
nameattribute with a value of"cheese". - a
valueof"no".
Comments
Post a Comment