You are here: Reference > JavaScript > client-side > HTML DOM > objects > nodes and tags > input:hidden
input:hidden object
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:
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:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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?
|
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?
|
Related pages:
External links:
input type='hidden' element (MSDN)
input type='hidden' element (Safari Reference Library)
input type='hidden' element (W3C)
input type='hidden' element (Safari Reference Library)
input type='hidden' element (W3C)
User Contributed Comments