Change the name of a hidden input field:
document.getElementById("myInput").name = "newName";
Click the buttons to display/change the value of the name attribute of the hidden input field.
<!DOCTYPE html> <html> <body> A hidden input field: <input type="hidden" id="myInput" name="country" value="Norway"> <p id="demo"></p> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("myInput").name; document.getElementById("demo").innerHTML = "The name of the hidden input field is: " + x; } function change() {// ww w. ja va2s . c o m var x = document.getElementById("myInput").name = "newName"; document.getElementById("demo").innerHTML = "The name was changed to: " + x; } </script> </body> </html>