Javascript DOM HTML Input Month name Property get

Introduction

Get the name of a month field:

var x = document.getElementById("myMonth").name;

Click the button to return the value of the name attribute of the month field.

input elements with type=month is not supported in Firefox.

The <input type="month"> element is not supported in Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>

Birthday (month and year): <input type="month" id="myMonth" name="bdaymonth">

<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {// w ww . j a  v a  2 s .com
  var x = document.getElementById("myMonth").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The name property sets or gets the value of the name attribute of a month field.

The name attribute is used to identify form data after it has been submitted to the server, or to reference form data using JavaScript on the client side.

Only form elements with a name attribute will have their values passed when submitting a form.

The name property accepts and returns a String type value.




PreviousNext

Related