/
index.md
67 lines (48 loc) · 1.42 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "RadioNodeList: value property"
short-title: value
slug: Web/API/RadioNodeList/value
page-type: web-api-instance-property
browser-compat: api.RadioNodeList.value
---
{{ APIRef("HTML DOM") }}
If the underlying element collection contains radio buttons, the
**`RadioNodeList.value`** property represents the checked radio
button. On retrieving the `value` property, the `value` of the
currently `checked` radio button is returned as a string. If the collection
does not contain any radio buttons or none of the radio buttons in the collection is in
`checked` state, the empty string is returned. On setting the
`value` property, the first radio button input element whose
`value` property is equal to the new value will be set to
`checked`.
## Syntax
```js-nolint
value = radioNodeList.value
radioNodeList.value = string
```
## Example
### HTML
```html
<form>
<label><input type="radio" name="color" value="blue" />Blue</label>
<label><input type="radio" name="color" value="red" />Red</label>
</form>
```
### JavaScript
```js
// Get the form
const form = document.forms[0];
// Get the form's radio buttons
const radios = form.elements["color"];
// Choose the "red" option
radios.value = "red";
```
### Result
{{EmbedLiveSample("Example")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The {{HTMLElement("form")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("input")}}
elements.