Change the name of a number field:
document.getElementById("myNumber").name = "newNumberName";
Click the buttons to display and change the value of the name attribute of the number field.
<!DOCTYPE html> <html> <body> <input type="number" id="myNumber" name="quantity"> <p id="demo"></p> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("myNumber").name; document.getElementById("demo").innerHTML = "The name of the number field is: " + x; } function change() {// w ww . jav a2 s . co m var x = document.getElementById("myNumber").name = "newNumberName"; document.getElementById("demo").innerHTML = "The name was changed to: " + x; } </script> </body> </html>