Javascript DOM HTML Input Hidden Object get

Introduction

The Input Hidden object represents an HTML <input> element with type="hidden".

We can access an <input> element with type="hidden" via document.getElementById():

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

Click the button to get the value of the hidden input field.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="hidden" id="myInput" value="Examples">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from  w  w w .  jav a 2 s  .c om*/
  var x = document.getElementById("myInput").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related