Table of Contents | Previous | Next | Index


Hidden

A Text object that is suppressed from form display on an HTML form. A Hidden object is used for passing name/value pairs when a form submits.

Client-side object

Implemented in

JavaScript 1.0

JavaScript 1.1: added type property

Created by

The HTML INPUT tag, with "hidden" as the value of the TYPE attribute. For a given form, the JavaScript runtime engine creates appropriate Hidden objects and puts these objects in the elements array of the corresponding Hidden object. You access a Hidden object by indexing this array. You can index the array either by number or, if supplied, by using the value of the NAME attribute.

Description

A Hidden object is a form element and must be defined within a FORM tag.

A Hidden object cannot be seen or modified by an end user, but you can programmatically change the value of the object by changing its value property. You can use Hidden objects for client/server communication.

Property Summary

Property Description
form

Specifies the form containing the Hidden object.

name

Reflects the NAME attribute.

type

Reflects the TYPE attribute.

value

Reflects the current value of the Hidden object.

Method Summary

This object inherits the watch and unwatch methods from Object.

Examples

The following example uses a Hidden object to store the value of the last object the user clicked. The form contains a "Display hidden value" button that the user can click to display the value of the Hidden object in an Alert dialog box.

<HTML>
<HEAD>
<TITLE>Hidden object example</TITLE>
</HEAD>
<BODY>
<B>Click some of these objects, then click the "Display value" button
<BR>to see the value of the last object clicked.</B>
<FORM NAME="myForm">
<INPUT TYPE="hidden" NAME="hiddenObject" VALUE="None">
<P>
<INPUT TYPE="button" VALUE="Click me" NAME="button1"
   onClick="document.myForm.hiddenObject.value=this.value">
<P>
<INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b"
   onClick="document.myForm.hiddenObject.value=this.value"> Soul and R&B
<INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz"
   onClick="document.myForm.hiddenObject.value=this.value"> Jazz
<INPUT TYPE="radio" NAME="musicChoice" VALUE="classical"
   onClick="document.myForm.hiddenObject.value=this.value"> Classical
<P>
<SELECT NAME="music_type_single"
   onFocus="document.myForm.hiddenObject.value=this.options[this.selectedIndex].text">
   <OPTION SELECTED> Red <OPTION> Orange <OPTION> Yellow
</SELECT>
<P><INPUT TYPE="button" VALUE="Display hidden value" NAME="button2"
   onClick="alert('Last object clicked: ' + document.myForm.hiddenObject.value)">
</FORM>
</BODY>
</HTML>

See also

document.cookie


form

An object reference specifying the form containing this object.

Property of

Hidden

Read-only

Implemented in

JavaScript 1.0

Description

Each form element has a form property that is a reference to the element's parent form. This property is especially useful in event handlers, where you might need to refer to another element on the current form.

Examples

Example 1. In the following example, the form myForm contains a Hidden object and a button. When the user clicks the button, the value of the Hidden object is set to the form's name. The button's onClick event handler uses this.form to refer to the parent form, myForm.

<FORM NAME="myForm">
Form name:<INPUT TYPE="hidden" NAME="h1" VALUE="Beluga">
<P>
<INPUT NAME="button1" TYPE="button" VALUE="Store Form Name"
   onClick="this.form.h1.value=this.form.name">
</FORM>
Example 2. The following example uses an object reference, rather than the this keyword, to refer to a form. The code returns a reference to myForm, which is a form containing myHiddenObject.

document.myForm.myHiddenObject.form

See also

Hidden


name

A string specifying the name of this object.

Property of

Hidden

Implemented in

JavaScript 1.0

Security

JavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.


type

For all Hidden objects, the value of the type property is "hidden". This property specifies the form element's type.

Property of

Hidden

Read-only

Implemented in

JavaScript 1.1

Examples

The following example writes the value of the type property for every element on a form.

for (var i = 0; i < document.myForm.elements.length; i++) {
   document.writeln("<BR>type is " + document.myForm.elements[i].type)
}

value

A string that reflects the VALUE attribute of the object.

Property of

Hidden

Implemented in

JavaScript 1.0

Security

JavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.

Examples

The following function evaluates the value property of a group of buttons and displays it in the msgWindow window:

function valueGetter() {
   var msgWindow=window.open("")
   msgWindow.document.write("The submit button says " +
      document.valueTest.submitButton.value + "<BR>")
   msgWindow.document.write("The reset button says " +
      document.valueTest.resetButton.value + "<BR>")
   msgWindow.document.write("The hidden field says " +
      document.valueTest.hiddenField.value + "<BR>")
   msgWindow.document.close()
}
This example displays the following values:

The submit button says Query Submit
The reset button says Reset
The hidden field says pipefish are cute.
The previous example assumes the buttons have been defined as follows:

<INPUT TYPE="submit" NAME="submitButton">
<INPUT TYPE="reset" NAME="resetButton">
<INPUT TYPE="hidden" NAME="hiddenField" VALUE="pipefish are cute.">

Table of Contents | Previous | Next | Index

Last Updated: 05/28/99 11:59:34

Copyright (c) 1999 Netscape Communications Corporation