Javascript DOM HTML Input Number name Property get

Introduction

Get the name of a number field:

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

Click the button to display the value of the name attribute of the number field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="number" id="myNumber" name="quantity">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

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

</body>
</html>

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

The name attribute can identify form data after submitting to the server.

Only form elements with a name attribute will be submitted to the server.

The name property accepts and returns a String type value.




PreviousNext

Related