Input Radio name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Radio

Description

The name property sets or gets the name attribute of a radio button.

Set the name property with the following Values

Value Description
name Sets the name of the radio button

Return Value

A String, representing the name of the radio button

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
<input type="radio" name="colors" value="red" id="myRadio">Red<br>
</form>/*  w  w  w . jav  a2 s .  co m*/



<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
    var x = document.getElementById("myRadio").name;
    console.log("The name of the radio button is: " + x);
}

function change() {
    var x = document.getElementById("myRadio").name = "newRadioName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials