You are here: Reference > JavaScript > client-side > HTML DOM > objects > nodes and tags > input:hidden

input:hidden object

Browser support:
Creates a hidden text control.
The control is not rendered, and it is invisible for the user. With this element you can send hidden data with a form to a server.
This control is one of the form controls.
The contents of the control can be submitted to a server if the following conditions are met:
  • A form element must contain the hidden control.
  • The action property of the container form must be set to the URL of the server.
  • The name property of the hidden control must be specified and non-empty.
When the container form is submitted, the name and the text content of the hidden control are sent as a name/value pair.
You can access the text content of the control with the value property. For example, if you create a custom check box on your form, you can use the hidden input element to send the state of the custom control. See Example 2 for details.

Syntax:

Methods that return the object:
var inputObj = document.createElement ("input");   inputObj.type = "hidden"
The base interface, through which you can add new functionalities to the input:hidden object, is the HTMLInputElement interface.
If you want to see the HTML objects by categories, please visit this page.
HTML page for this element: input:hidden

Possible members:

Properties
Methods
Events
Style properties
attributes
Represents a collection of attribute nodes that belong to an element.
baseURI
10
Returns the base URL for the object.
behaviorUrns
Represents a collection of the Uniform Resource Names for all behaviors attached to an element.
canHaveChildren
Retrieves a Boolean value that indicates whether the element can contain child elements.
canHaveHTML
Retrieves a Boolean value that indicates whether the element can contain HTML formatted text.
className
Sets or retrieves the style class or classes that belong to the element.
currentStyle
Represents the computed style settings for an element.
dataFld
Specifies or returns which field of a given data source should be bound to the specified object.
dataSrc
Sets or retrieves the identifier of the data source that is bound to the element.
defaultValue
Specifies or returns the initial value of the object. The initial state can be set with the value attribute in HTML.
filters
Represents a collection of all filter objects applied to an element.
form
Returns a reference to the form element in which the object is placed.
forms
Represents a collection of all form elements in the current document.
hideFocus
Specifies or returns whether a dotted rectangle (focus rectangle) is drawn around an object while it has focus.
id
Sets or retrieves a unique identifier for the object.
isContentEditable
Returns a Boolean value that indicates whether the contents of the object are editable by the user.
isDisabled
Returns a Boolean value that indicates whether the object is disabled.
isMultiLine
Returns a Boolean value that indicates whether the contents of an element can be multiline or not.
isTextEdit
Returns a Boolean value that indicates whether the createTextRange method can be used for the element.
lang
Specifies or returns the language of the element.
language
Sets or retrieves the scripting language for the current element. Use it only for the script element.
localName
9
Returns the local part of the qualified name of the current node.
name
Sets or retrieves the name of a form control that affects the contents of the message submitted to the server.
namespaceURI
93.6
Sets or returns the namespace URI of the current node.
nextElementSibling
93.5
Returns a reference to the next child element of the current element's parent.
nextSibling
Returns a reference to the next child of the current element's parent.
nodeName
Returns the name of the current node.
nodeType
Returns an integer that indicates the type of the node.
nodeValue
Sets or returns the value of the current node.
outerHTML
Sets or retrieves the outer HTML content (the source code including the opening and closing tags) of an element.
outerText
Sets or returns the text content of an element including the text content of its descendants.
ownerDocument
Returns the document object that contains the current node.
parentElement
Returns the parent element of the object in the DOM hierarchy.
parentNode
Returns the parent element of the current node in the DOM hierarchy.
parentTextEdit
Returns the closest ancestor element of the current element in the DOM hierarchy that can be used to create a TextRange object.
previousElementSibling
93.5
Returns a reference to the previous child element of the current element's parent.
previousSibling
Returns a reference to the previous node of the current element's parent.
readyState
Returns a string value that represents the state of the object.
recordNumber
Returns an integer value that indicates the ordinal position of the item within the data set that generated the current object.
runtimeStyle
Represents the overridden style settings for an element.
scopeName
Retrieves the local name of the namespace declared for the current element.
sourceIndex
Returns the position of the current object in the all collection of the document.
style
Represents the inline style settings for an element or a CSS rule.
tagName
Returns the tag name of the current element.
tagUrn
Sets or retrieves the Uniform Resource Name (URN) of the namespace declared for the current element.
textContent
9
Sets or returns the text content of an element including the text content of its descendants.
textLength
Returns the length of the text in a form control.
type
Sets or retrieves the type of the input element.
uniqueID
Returns the unique identifier generated by the browser for the object.
unselectable
Sets or retrieves whether the selection process can start in an element's content.
value
Specifies or returns the value of the control.

Example HTML code 1:

This example illustrates the use of the hidden input element. For example, if you want know how long it takes the user to fill a registration form, simply create a hidden input field with a value of the actual server time when generating the registration form on the server. When the form is submitted, you can get the duration from this value.
<form method="post" action="#URL#">
    <input type="hidden" value="19:03:31" name="startTime" />
    Username: <input type="text" name="userName" />
    <br />
    Email: <input type="text" name="email" />
    <br />
    Password: <input type="password" name="password" />
    <br />
    Repeat Password: <input type="password" name="repassword" />
    <br /><br />
    <input type="submit" value="Register" />
</form>
Did you find this example helpful? yes no

Example HTML code 2:

This example creates a custom check box element (a span element). The red color represents the unchecked state, the blue color represents the checked state. The example uses a hidden input element to submit a state of a custom check box:
<head>
    <style>
        .unchecked {
            width:15px;
            height:15px;
            margin-right:10px;
            border:1px solid blue;
            background-color:red;
        }
        .checked {
            width:15px;
            height:15px;
            margin-right:10px;
            border:1px solid red;
            background-color:blue;
        }
    </style>
    <script type="text/javascript">
        function ToggleState (elem) {
            if (elem.className == "unchecked")
                elem.className = "checked";
            else
                elem.className = "unchecked";
        }

        function CheckAndSubmit () {
            var regForm = document.getElementById ("regForm");
            var acceptAgreementCustom = document.getElementById ("acceptAgreementCustom");
            var acceptAgreement = document.getElementById ("acceptAgreement");

                // set the value of the hidden input element to "checked" or "unchecked"
            acceptAgreement.value = acceptAgreementCustom.className;

            if (acceptAgreement.value != "checked") {
                alert ("You must accept the User Agreement to register!");
                return;
            }

            regForm.submit ();
        }
    </script>
</head>
<body>
    <form id="regForm" method="post" action="#URL#">
        <span class="unchecked" onclick="ToggleState (this)" id="acceptAgreementCustom"></span> <!-- the custom check box -->
        <label for="acceptAgreementCustom">I accept the User Agreement and Privacy Policy</label>
        <input type="hidden" name="acceptAgreement" id="acceptAgreement" /> 
        <br /><br />
        <input type="button" value="Register" onclick="CheckAndSubmit ()" />
    </form>
</body>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content