Change the name of a checkbox:
document.getElementById("myRadio").name = "newRadioName";
Click the buttons to display and change the value of the name attribute of the radio button.
<!DOCTYPE html> <html> <body> <form> <input type="radio" name="colors" value="red" id="myRadio">Red<br> </form>/*from w ww . jav a 2 s.com*/ <p id="demo"></p> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("myRadio").name; document.getElementById("demo").innerHTML = "The name of the radio button is: " + x; } function change() { var x = document.getElementById("myRadio").name = "newRadioName"; document.getElementById("demo").innerHTML = "The name was changed to: " + x; } </script> </body> </html>