HTML Hidden Field (HTML Forms tutorials part 11)

১১/১৮/২০১১ ০৯:২৬:০০ AM | | 0 comments »

Hidden fields are not displayed by the browser, there are a number of uses for them. When dealing with forms you will usually find yourself using some sort of database mechanism: MySQL, SQL Server, or maybe justa plain text file. In any case use hidden forms to pass along information to your database that may have already been received from the user. In this rare case, a hidden form field may come in handy.

A hidden HTML field is used to pass along variables w/ values from one form to another page without forcing the user to re-enter the information. Use the type attribute to specify a hidden field.

HTML Code:

<input type="hidden" />

Hidden Fields:

There is no display of your hidden field in the box because the browser is told to hide them from view. Our field above is incomplete and pretty much useless as it is. Adding a name and a value attribute will change this.

HTML - Name and Value the Fields

Naming your fields can be accomplished in two different ways discussed previously. Use the id or name attribute to specify a name for your hidden field.

HTML Code:

<input type="hidden" id="age" name="age" value="23" />
<input type="hidden" id="DOB" name="DOB" value="01/01/70" />
<input type="hidden" id="admin" name="admin" value="1" />
Above we have demonstrated 3 possible hidden fields that you may want to pass along some form at some point, especially if you have any kind of user base where returning users must log in. The admin field could be used to check some sort of user level entry of a returning user; 1 being administrator and 0 being non-administrator access.
Use hidden fields when you have variables you want to pass from one form to another without forcing the user to re-type information over and over again.