Input Hidden value Attribute

Definition and Usage

value Sets or returns the value of the 'value' attribute of a hidden input field.

The 'value' attribute of HTML defines the default value of a hidden input field.

See also:

HTML Reference Manual:HTML <input> value Attribute

Example

Example 1

Get the value of the 'value' attribute of a hidden input field:

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

Try it yourself

Example 2

Change the value of a hidden field:

document.getElementById("myInput").value = "USA";

Try it yourself

Example 3

Submit the form - How to change the value of a hidden field:

document.getElementById("myInput").value = "USA";
document.getElementById("demo").innerHTML = "The value of the 'value' attribute has been changed. Please try submitting the form again.";

Try it yourself

Syntax

Return value attribute:

hiddenObject.value

Set value attribute:

hiddenObject.value = text

Attribute Value

Value Description
text Specifies the initial (default) value of the input field.

Technical Details

Return Value: A string value representing the value of the hidden input field's value attribute.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support