Javascript DOM HTML Input DatetimeLocal name Property set

Introduction

Change the name of a local datetime field:

document.getElementById("myLocalDate").name = "newDatetimeName";

Click the buttons to display/change the name attribute of the local datetime field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Birthday: <input type="datetime-local" id="myLocalDate" 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("myLocalDate").name;
  document.getElementById("demo").innerHTML = "The name of the local datetime field is: " + x;
}

function change() {/*from   w  w w  .  j a va2s .  c om*/
  var x = document.getElementById("myLocalDate").name = "newDatetimeName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related