2018-09-30 23:01:58 +01:00
---
id: bad87fee1348bd9aedf08835
title: Create a Set of Checkboxes
challengeType: 0
videoUrl: 'https://scrimba.com/p/pVMPUv/cqrkJsp'
2019-07-31 11:32:23 -07:00
forumTopicId: 16821
2021-01-13 03:31:00 +01:00
dashedName: create-a-set-of-checkboxes
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2019-10-27 15:45:37 -01:00
Forms commonly use < dfn > checkboxes< / dfn > for questions that may have more than one answer.
2020-11-27 19:02:05 +01:00
Checkboxes are a type of `input` .
Each of your checkboxes can be nested within its own `label` element. By wrapping an `input` element inside of a `label` element it will automatically associate the checkbox input with the label element surrounding it.
All related checkbox inputs should have the same `name` attribute.
It is considered best practice to explicitly define the relationship between a checkbox `input` and its corresponding `label` by setting the `for` attribute on the `label` element to match the `id` attribute of the associated `input` element.
2018-09-30 23:01:58 +01:00
Here's an example of a checkbox:
2020-11-27 19:02:05 +01:00
`<label for="loving"><input id="loving" type="checkbox" name="personality"> Loving</label>`
# --instructions--
Add to your form a set of three checkboxes. Each checkbox should be nested within its own `label` element. All three should share the `name` attribute of `personality` .
# --hints--
Your page should have three checkbox elements.
```js
assert($('input[type="checkbox"]').length > 2);
```
Each of your three checkbox elements should be nested in its own `label` element.
```js
assert($('label > input[type="checkbox"]:only-child').length > 2);
```
Make sure each of your `label` elements has a closing tag.
```js
assert(
code.match(/< \/label > /g) &&
code.match(/< label / g ) & &
code.match(/< \/label > /g).length === code.match(/< label / g ). length
);
```
Your checkboxes should be given the `name` attribute of `personality` .
```js
assert(
$('label > input[type="checkbox"]').filter('[name="personality"]').length > 2
);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
Each of your checkboxes should be added within the `form` tag.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert($('label').parent().get(0).tagName.match('FORM'));
```
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
```html
< h2 > CatPhotoApp< / h2 >
< main >
< p > Click here to view more < a href = "#" > cat photos< / a > .< / p >
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< a href = "#" > < img src = "https://bit.ly/fcc-relaxing-cat" alt = "A cute orange cat lying on its back." > < / a >
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< p > Things cats love:< / p >
< ul >
< li > cat nip< / li >
< li > laser pointers< / li >
< li > lasagna< / li >
< / ul >
< p > Top 3 things cats hate:< / p >
< ol >
< li > flea treatment< / li >
< li > thunder< / li >
< li > other cats< / li >
< / ol >
2020-07-15 02:56:49 -07:00
< form action = "https://freecatphotoapp.com/submit-cat-photo" >
2018-09-30 23:01:58 +01:00
< label for = "indoor" > < input id = "indoor" type = "radio" name = "indoor-outdoor" > Indoor< / label >
< label for = "outdoor" > < input id = "outdoor" type = "radio" name = "indoor-outdoor" > Outdoor< / label > < br >
< input type = "text" placeholder = "cat photo URL" required >
< button type = "submit" > Submit< / button >
< / form >
< / main >
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2019-04-22 02:07:05 -04:00
```html
< h2 > CatPhotoApp< / h2 >
< main >
< p > Click here to view more < a href = "#" > cat photos< / a > .< / p >
< a href = "#" > < img src = "https://bit.ly/fcc-relaxing-cat" alt = "A cute orange cat lying on its back." > < / a >
< p > Things cats love:< / p >
< ul >
< li > cat nip< / li >
< li > laser pointers< / li >
< li > lasagna< / li >
< / ul >
< p > Top 3 things cats hate:< / p >
< ol >
< li > flea treatment< / li >
< li > thunder< / li >
< li > other cats< / li >
< / ol >
2020-07-15 02:56:49 -07:00
< form action = "https://freecatphotoapp.com/submit-cat-photo" >
2019-04-22 02:07:05 -04:00
< label for = "indoor" > < input id = "indoor" type = "radio" name = "indoor-outdoor" > Indoor< / label >
< label for = "outdoor" > < input id = "outdoor" type = "radio" name = "indoor-outdoor" > Outdoor< / label > < br >
< label for = "playful" > < input id = "playful" type = "checkbox" name = "personality" > Playful< / label >
< label for = "lazy" > < input id = "lazy" type = "checkbox"
name="personality">Lazy< / label >
< label for = "evil" > < input id = "evil" type = "checkbox"
name="personality">Evil< / label > < br >
< input type = "text" placeholder = "cat photo URL" required >
< button type = "submit" > Submit< / button >
< / form >
< / main >
2018-09-30 23:01:58 +01:00
```