Radio value Property
Radio Object
Definition and Usage
The value property sets or returns the value of the value attribute of the
radio button.
For radio buttons, the contents of the value property do not appear in the
user interface. The value property only has meaning when submitting a form. If a
radio button is in checked state when the form is submitted, the name of the
radio button is sent along with the value of the value property (if the radio
button is not checked, no information is sent).
Tip: Define different values for radio buttons in the same group, to
identify (on the server side) which one was checked.
Syntax
Set the value property:
radioObject.value="value"
Return the value property:
Browser Support

The value property is supported in all major browsers.
Examples
Example 1
Display the value of the "Red" radio button:
<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("red").value;
alert(x);
}
</script>
</head>
<body>
<form>
What color do you prefer?<br>
<input type="radio" name="colors" id="red" value="red">Red<br>
<input type="radio" name="colors" id="blue" value="blue">Blue<br>
<input type="radio" name="colors" id="green" value="green">Green
</form>
<button type="button" onclick="displayResult()">Display value</button>
</body>
</html>
Try it yourself »
Example 2
Display the value of the selected radio button:
<html>
<head>
<script>
function displayResult(browser)
{
document.getElementById("result").value=browser
}
</script>
</head>
<body>
<p>Select your favorite browser:</p>
<form>
<input type="radio" name="browser" onclick="displayResult(this.value)"
value="Internet Explorer">Internet Explorer<br>
<input type="radio" name="browser" onclick="displayResult(this.value)"
value="Firefox">Firefox<br>
<input type="radio" name="browser" onclick="displayResult(this.value)"
value="Opera">Opera<br>
<input type="radio" name="browser" onclick="displayResult(this.value)"
value="Google Chrome">Google Chrome<br>
<input type="radio" name="browser" onclick="displayResult(this.value)"
value="Safari">Safari<br><br>
Your favorite browser is: <input type="text" id="result">
</form>
</body>
</html>
Try it yourself »
Radio Object
Thank You For Helping Us!
Your message has been sent to W3Schools.
Close [X]