2019-03-25 00:43:05 +01:00
---
id: 5c6c06847491271903d37cfd
title: Use the value attribute with Radio Buttons and Checkboxes
challengeType: 0
2019-08-05 09:17:33 -07:00
forumTopicId: 301099
2021-01-13 03:31:00 +01:00
dashedName: use-the-value-attribute-with-radio-buttons-and-checkboxes
2019-03-25 00:43:05 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
When a form gets submitted, the data is sent to the server and includes entries for the options selected. Inputs of type `radio` and `checkbox` report their values from the `value` attribute.
2019-03-25 00:43:05 +01:00
For example:
2019-05-14 01:11:58 -07:00
```html
2020-09-02 10:19:47 -04:00
< label for = "indoor" >
< input id = "indoor" value = "indoor" type = "radio" name = "indoor-outdoor" > Indoor
2019-05-14 01:11:58 -07:00
< / label >
2020-09-02 10:19:47 -04:00
< label for = "outdoor" >
< input id = "outdoor" value = "outdoor" type = "radio" name = "indoor-outdoor" > Outdoor
2019-05-14 01:11:58 -07:00
< / label >
```
2020-11-27 19:02:05 +01:00
Here, you have two `radio` inputs. When the user submits the form with the `indoor` option selected, the form data will include the line: `indoor-outdoor=indoor` . This is from the `name` and `value` attributes of the "indoor" input.
If you omit the `value` attribute, the submitted form data uses the default value, which is `on` . In this scenario, if the user clicked the "indoor" option and submitted the form, the resulting form data would be `indoor-outdoor=on` , which is not useful. So the `value` attribute needs to be set to something to identify the option.
# --instructions--
Give each of the `radio` and `checkbox` inputs the `value` attribute. Use the input label text, in lowercase, as the value for the attribute.
# --hints--
One of your radio buttons should have the `value` attribute of `indoor` .
```js
assert(
$('label:contains("Indoor") > input[type="radio"]').filter("[value='indoor']")
.length > 0
);
```
One of your radio buttons should have the `value` attribute of `outdoor` .
2019-03-25 00:43:05 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
$('label:contains("Outdoor") > input[type="radio"]').filter(
"[value='outdoor']"
).length > 0
);
```
2019-03-25 00:43:05 +01:00
2020-11-27 19:02:05 +01:00
One of your checkboxes should have the `value` attribute of `loving` .
2019-03-25 00:43:05 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
$('label:contains("Loving") > input[type="checkbox"]').filter(
"[value='loving']"
).length > 0
);
```
2019-03-25 00:43:05 +01:00
2020-11-27 19:02:05 +01:00
One of your checkboxes should have the `value` attribute of `lazy` .
2019-03-25 00:43:05 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
$('label:contains("Lazy") > input[type="checkbox"]').filter("[value='lazy']")
.length > 0
);
2019-03-25 00:43:05 +01:00
```
2020-11-27 19:02:05 +01:00
One of your checkboxes should have the `value` attribute of `energetic` .
2019-03-25 00:43:05 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
$('label:contains("Energetic") > input[type="checkbox"]').filter(
"[value='energetic']"
).length > 0
);
```
2019-03-25 00:43:05 +01:00
2020-11-27 19:02:05 +01:00
# --seed--
## --seed-contents--
2019-03-25 00:43:05 +01:00
```html
< h2 > CatPhotoApp< / h2 >
< main >
< p > Click here to view more < a href = "#" > cat photos< / a > .< / p >
2020-09-02 10:19:47 -04:00
2019-03-25 00:43:05 +01:00
< a href = "#" > < img src = "https://bit.ly/fcc-relaxing-cat" alt = "A cute orange cat lying on its back." > < / a >
2020-09-02 10:19:47 -04:00
2019-03-25 00:43:05 +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" >
2020-09-02 10:19:47 -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 = "loving" > < input id = "loving" type = "checkbox" name = "personality" > Loving< / label >
< label for = "lazy" > < input id = "lazy" type = "checkbox" name = "personality" > Lazy< / label >
< label for = "energetic" > < input id = "energetic" type = "checkbox" name = "personality" > Energetic< / label > < br >
2019-03-25 00:43:05 +01:00
< input type = "text" placeholder = "cat photo URL" required >
< button type = "submit" > Submit< / button >
< / form >
< / main >
```
2020-11-27 19:02:05 +01:00
# --solutions--
2019-03-25 00:43:05 +01:00
```html
< h2 > CatPhotoApp< / h2 >
< main >
< p > Click here to view more < a href = "#" > cat photos< / a > .< / p >
2020-09-02 10:19:47 -04:00
2019-03-25 00:43:05 +01:00
< a href = "#" > < img src = "https://bit.ly/fcc-relaxing-cat" alt = "A cute orange cat lying on its back." > < / a >
2020-09-02 10:19:47 -04:00
2019-03-25 00:43:05 +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" >
2020-09-02 10:19:47 -04:00
< label for = "indoor" > < input id = "indoor" type = "radio" name = "indoor-outdoor" value = "indoor" > Indoor< / label >
< label for = "outdoor" > < input id = "outdoor" type = "radio" name = "indoor-outdoor" value = "outdoor" > Outdoor< / label > < br >
< label for = "loving" > < input id = "loving" type = "checkbox" name = "personality" value = "loving" > Loving< / label >
< label for = "lazy" > < input id = "lazy" type = "checkbox" name = "personality" value = "lazy" > Lazy< / label >
< label for = "energetic" > < input id = "energetic" type = "checkbox" name = "personality" value = "energetic" > Energetic< / label > < br >
2019-03-25 00:43:05 +01:00
< input type = "text" placeholder = "cat photo URL" required >
< button type = "submit" > Submit< / button >
< / form >
< / main >
```