Javascript DOM HTML Input Date name Property set

Introduction

Change the name of a date field:

document.getElementById("myDate").name = "newDateName";

Click the buttons to display/change the value of the name attribute of the date field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Birthday: <input type="date" id="myDate" name="bday">
<p id="demo"></p>
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<script>
function display() {
  var x = document.getElementById("myDate").name;
  document.getElementById("demo").innerHTML = "The name of the date field is: " + x;
}

function change() {/*from ww  w .  j  ava 2  s  . c om*/
  var x = document.getElementById("myDate").name = "newDateName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related