JavaScript Tutorial/Form/Hidden Object

Материал из Web эксперт
Перейти к: навигация, поиск

Hidden

The Hidden object is created with the HTML <input> tag. Specifying the TYPE parameter of the <input> tag as hidden creates the Hidden object. It is a text object that is suppressed from form display in an HTML form. The Hidden object is primarily used for passing name/value pairs from a form.

Property Description form Specifies the form containing the Hidden object. name Refers to the name of Hidden object. type Refers to HTML TYPE attribute of Hidden object. value Refers to HTML VALUE attribute of Hidden object.



<html>
    <head>
    <title> Creating hidden objects</title>
    </head>
    <body>
    <form name="form1">
    <input type="hidden" name="hide1" value="Test">
    <P>
    <input type="button" value="Get Hidden Attributes"
         onClick="alert(form1.hide1.name + " " + form1.hide1.type + " " + form1.hide1.value)">
    </form>
    </body>
    </html>


Hidden.form

The form property of the Hidden object is used to reference the form containing the Hidden object.



<html>
    <head>
    <title> Using the form property of the Hidden object</title>
    </head>
    <body>
    <form name="form1">
    Form name:<input type="hidden" name="hide1" value="Test">
    <P>
    <input type="button" value="Form Name"
       onClick="this.form.hide1.value=this.form.name">
    </form>
    </body>
    </html>


Hidden.name

The name property is used get the name for the Hidden object.

This is the HTML NAME attribute for the Hidden object.



<html>
    <head>
    <title> Using the name property of the Hidden object</title>
    </head>
    <body>
    <form name="form1">
    Form name:<input type="hidden" name="hide1" value="Test">
    <P>
    <input type="button" value="Hidden Name"
       onClick="alert("The Hidden object name is: " + form1.hide1.name)">
    </form>
    </body>
    </html>


Hidden.type

The type property specifies the hidden type.

For all Hidden objects, the type value is Hidden.



<html>
    <head>
    <title> Using the type property of the Hidden object</title>
    </head>
    <body>
    <form name="form1">
    Form name:<input type="hidden" name="hide1" value="Test">
    <P>
    <input type="button" value="Hidden Type"
       onClick="alert("The Hidden object type is: " + form1.hide1.type)">
    </form>
    </body>
    </html>


Hidden.value

The value property reflects the HTML VALUE attribute of the Hidden object.



<html>
    <head>
    <title> Using the value property of the Hidden Object</title>
    </head>
    <body>
    <form name="form1">
    Form name:<input type="hidden" name="hide1" value="Test">
    <P>
    <input type="button" value="Get Hidden Value"
       onClick="alert("The Hidden object value is: " + form1.hide1.value)">
    </form>
    </body>
    </html>