Change the name of a datetime field:
document.getElementById("myDatetime").name = "newDatetimeName"; Click the buttons to display/change the value of the name attribute of the datetime field.
<!DOCTYPE html> <html> <body> Birthday: <input type="datetime" id="myDatetime" name="bdaytime"> <p id="demo"></p> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("myDatetime").name; document.getElementById("demo").innerHTML = "The name of the datetime field is: " + x; } function change() {/* w ww . ja v a 2 s .c o m*/ var x = document.getElementById("myDatetime").name = "newDatetimeName"; document.getElementById("demo").innerHTML = "The name was changed to: " + x; } </script> </body> </html>