Полезная информация

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Element.name Property

Name

Element.name Property---the name of a form element

Availability

Navigator 2.0, Internet Explorer 3.0

Synopsis

element.name

Description

name is a read-only string property of every form element. The value of this property is set by the NAME attributes of the HTML <INPUT> tag that defines the form element.

The name of a form element is used for two purposes. First, it is used when the form is submitted. Data for each element in the form is usually submitted in the format:

name=value

where name and value are encoded as necessary for transmission. If a name is not specified for a form element, then the data for that element cannot be meaningfully submitted to a web server.

The second use of the name property is to refer to a form element in JavaScript code. The name of an element becomes a property of the form that contains the element. The value of this property is a reference to the element. For example, if address is a form that contains a text input element with the name zip, then address.zip refers to that text input element.

With Radio and Checkbox form elements, it is common to define more than one related object, each of which have the same name property. In this case, data is submitted to the server with this format:

name=value1,value2,...,valuen

Similarly, in JavaScript, each of the elements that shares a name becomes an element of an array with that name. Thus if four Checkbox objects in the form order share the name "options," then they are available in JavaScript as elements of the array order.options[].

Bugs

In Navigator 2.0, when multiple form elements are given the same name and placed in an array, they will only be placed in the array in the expected source order if they all define an event handler, even a dummy event handler that does nothing. If none of the elements define event-handlers, then they will be inserted into the array in reverse order. If some define event handlers and others don't, the order will be less predictable. In cases where array order actually matters, the workaround to this bug is to define dummy event handlers as needed.

See Also

"Element"


Previous Home Next
Element.length Book Index Element.onblur()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell