Input Radio value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Radio

Description

The value property sets or gets the value attribute of the radio button.

Set the value property with the following Values

Value Description
text Sets the value associated with the input

Return Value

A String, representing the value of the value attribute of the radio button

The following code shows how to get the value of the value attribute of a radio button:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Select your favorite browser:</p>
<form action="#">
  <input type="radio" name="browser" onclick="myFunction(this.value)" value="Internet Explorer">Internet Explorer<br>
  <input type="radio" name="browser" onclick="myFunction(this.value)" value="Firefox">Firefox<br>
  <input type="radio" name="browser" onclick="myFunction(this.value)" value="Opera">Opera<br>
  <input type="radio" name="browser" onclick="myFunction(this.value)" value="Google Chrome">Google Chrome<br>
  <input type="radio" name="browser" onclick="myFunction(this.value)" value="Safari">Safari<br><br>

  Your favorite browser is: <input type="text" id="result">
  <input type="submit" value="Submit form">
</form>//w ww .  j  a  va2s .  co m

<script>
function myFunction(browser) {
    document.getElementById("result").value = browser;
}
</script>

</body>
</html>

Related Tutorials