W3Schools.com

Radio value Property

Radio Object Reference 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:

radioObject.value


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The value property is supported in all major browsers.


Examples

Example 1

Display the value of the "Red" radio button:

<html>
<head>
<script type="text/javascript">
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 type="text/javascript">
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 Reference Radio Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE