Hi guys,
I just had a quick question:
<fieldset>
<legend>Account type (required)</legend>
<label><input type="radio" name="account-type" checked /> Personal</label>
<label><input type="radio" name="account-type" /> Business</label>
</fieldset>
In this piece of code it only required me to add the checked attribute to one of the input elements i was just wondering why add only one and if there were more radio types in the same field set would I add the checked attribute to all but one of them, or still only add one checked attribute?
I also dont really understand its necessity if i have the legend element.
Sorry for the list of questions.
I have edited your post so that your code displays correctly on the forum. When you post code here, you should enclose it between two sets of triple backticks. You can do this manually or use the Preformatted Text tool (</>
icon or CTRL+e).
You add a checked
attribute to the first of each group of radio buttons, as that is standard practice for forms. This means that the user will see that the first radio button of a group is selected by default. As the radio buttons are part of a group, only one can be selected at a time, so the user can click on any radio button to change the selection to the appropriate option.
In your code, the user is asked to select whether their account type is ‘Personal’ or ‘Business’. The ‘Personal’ option is selected by default.
1 Like
Hello! Nice to see you!
The following article from FCC News category, may help to understand attributes better.
As @igorgetmeabrain has provided the direct answer, I thought this may help in the future.
Keep up the good progress.
1 Like
Hi guys,
Firstly apologies for not including my code in the proper format, I will do my best to remember to present it properly in future.
Secondly thank you for clearing up my confusion about the “checked” attribute and thank you for the additional link I will be sure to check it out and keep it as a reference for my studies in future.
Thank you again to both of you that replied.
Regards
Zaki
1 Like
You are very welcome!
Keep up yourgood progress!
Happy coding!