Hidden
AText 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.Created by
The HTMLINPUT 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
AHidden 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
|
|
|
| |
|---|
Method Summary
This object inherits thewatch and unwatch methods from Object.
Examples
The following example uses aHidden 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.Description
Each form element has aform 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 formmyForm 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">Example 2. The following example uses an object reference, rather than the
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>
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.Security
JavaScript 1.1. This property is tainted by default. For information on data tainting, see the Client-Side JavaScript Guide.type
For allHidden objects, the value of the type property is "hidden". This property specifies the form element's type. Examples
The following example writes the value of thetype 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 theVALUE attribute of the object.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 thevalue property of a group of buttons and displays it in the msgWindow window:
function valueGetter() {This example displays the following values:
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()
}
The submit button says Query SubmitThe previous example assumes the buttons have been defined as follows:
The reset button says Reset
The hidden field says pipefish are cute.
<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
