Get the value attribute of a hidden input field:
var x = document.getElementById("myInput").value;
Click the button to display the value attribute of the hidden input field.
<!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 ww. j av a2 s .c o m var x = document.getElementById("myInput").value; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The value property sets or gets the value attribute of the hidden input field.
The value attribute defines the default value of the hidden input field.
The value property accepts and returns a String type value.
Value | Description |
---|---|
text | Specifies the initial (default) value of the input field |
The value property returns a String representing the value attribute of the hidden input field.