Input Radio name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Radio


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>

<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>

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);


Related Tutorials