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 |
A String, representing the name of the radio button
The following code shows how to get the name of a radio button:
<!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>