Javascript DOM HTML Input Month name Property set

Introduction

Change the name of a month field:

document.getElementById("myMonth").name = "newMonthName";

Click the buttons to display and change the value of the name attribute of the month field.

input elements with type=month is not supported in Firefox.</p>

View in separate window

<!DOCTYPE html>
<html>
<body>

Birthday (month and year): <input type="month" id="myMonth" name="bdaymonth">
<p id="demo"></p>
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
  var x = document.getElementById("myMonth").name;
  document.getElementById("demo").innerHTML = "The name of the month field is: " + x;
}

function change() {//from   ww w.java 2  s.  c  o  m
  var x = document.getElementById("myMonth").name = "newMonthName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related