Javascript DOM HTML Input Hidden name Property get

Introduction

Get the name of a hidden input field:

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

Click the button to display the value of the name attribute of the hidden input field.

View in separate window

<!DOCTYPE html>
<html>
<body>

A hidden input field: <input type="hidden" id="myInput" name="myname">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  w w  w.j a v a  2 s.c o  m*/
  var x = document.getElementById("myInput").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The name property sets or gets the value of the name attribute of a hidden input 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.

Value Description
name Specifies the name of the hidden input field

The name property returns a String, representing the name of the hidden input field.




PreviousNext

Related