Online Documentation Server
 ÏÎÈÑÊ
ods.com.ua Web
 ÊÀÒÅÃÎÐÈÈ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ÏÎÄÏÈÑÊÀ

 Î ÊÎÏÈÐÀÉÒÀÕ
Âñÿ ïðåäîñòàâëåííàÿ íà ýòîì ñåðâåðå èíôîðìàöèÿ ñîáðàíà íàìè èç ðàçíûõ èñòî÷íèêîâ. Åñëè Âàì êàæåòñÿ, ÷òî ïóáëèêàöèÿ êàêèõ-òî äîêóìåíòîâ íàðóøàåò ÷üè-ëèáî àâòîðñêèå ïðàâà, ñîîáùèòå íàì îá ýòîì.




Previous Table of Contents Next

You can use this function by invoking it with a specific form’s reference and a name. Consider the following simple HTML form:

<FORM NAME="form1" ACTION="http://www.yourserver.com/filename.cgi"
 METHOD="post">
<INPUT TYPE="text" NAME="num1" VALUE="bla">
<INPUT TYPE="hidden" NAME="num2" VALUE="foo">
<TEXTAREA NAME="num3">wow</TEXTAREA>
</FORM>

The preceding printElements() function returns the following output when provided with the arguments document.forms[0] and "document.forms[0]":

Notice that the first four lines list the exclusive properties of the elements object. The following lines represent properties of elements which are identical to those of the form itself, document.forms[0] in this case. Theoretically, you can reference all forms properties of a given form as properties of its elements object.

If you think this wealth of referencing methods is confusing, you are right. The best way to get out of it is to stick to some standards. Suppose you have a form in a document which is referenced as document.forms[index], document.formName, or formReference. The following objects include all forms properties:

formReference
formReference.elements

The elements property of formReference is just another interface to the same object. Since Netscape originally documented the above two objects as different ones (and still does), it is common to refer to formReference when accessing a form’s general properties and to formReference.elements when accessing the properties of the form’s elements. Theoretically, you can also access the first element of the form by:

formReference[0]

As you already know, any form element object can be referenced by its name. For example, a text object whose name is “field1” in the first form of a page can be accessed as follows:

document.forms[0].field1

When two or more elements have the same name, they form an array in which the indices are determined according to their layout order. For example, if there are three text objects in one form, all named inputField, you can reference these elements in the following fashion:

document.forms[0].inputField[0]
document.forms[0].inputField[1]
document.forms[0].inputField[2]

encoding

The content of a form is encoded before it is submitted to the server. There are various types of encoding, or MIME encoding, some suitable for files, while others are suitable for plain text or other purposes. The encoding method is initially specified by assigning it to the <FORM> tag’s ENCTYPE attribute. The default encoding method is application/x-www-form-urlencoded, but others such as multipart/form-data and text/plain are also available.

Every HTML form has a MIME encoding specification, even if it is not explicitly shown. The value of JavaScript’s formReference.encoding is initially the value assigned to the HTML ENCTYPE attribute. This property is not read-only, so it can be set at any time, even after layout has been completed. Setting encoding overrides the ENCTYPE attribute and instructs the browser (primarily Navigator) to use the new MIME encoding method. For your reference, the general syntax of this property is as follows:

formReference.encoding

If no value is specified as the ENCTYPE attribute of a form, it is defaulted to application/x-www-form-urlencoded. Nevertheless, the value of formReference.encoding remains an empty string.

method

The METHOD attribute of a <FORM> tag accepts either a “get” or a “post” value. JavaScript reflects the value of this attribute in the form of a method property. You can use this property like all other form properties. It can be read or set at any time, even after layout has been completed. The term “method,” in this case, has no relation whatsoever to the object-oriented interpretation of the word (a function associated with an object).

The formReference.method property is when the client-side JavaScript script interacts with a specific server-side CGI or LiveWire application. In this case, you can set the method property along with other form-related properties to modify the form’s layout “on-the-fly.” The general syntax to reference this property is:

formReference.method

The default value of the HTML METHOD attribute is get. The value of the JavaScript method property, however, has no default and stays empty.

target

When you “surf the Web,” you often encounter HTML forms that submit data to the server and return a result, such as a list of sites or a simple “Thank You” page. Since most forms serve as a means to interact with the user, you will seldom find forms that submit to the server and do not respond. Furthermore, even forms that just receive input from the user and submit it to a server-side script are expected to respond and give the user an indication that the content of the form was correctly submitted.

Most server-side applications return a new HTML page in the same window as the form. Sometimes, however, you intend to receive the results in a different window or frame. You can specify the target of the returned page by setting the TARGET attribute of the <FORM> tag. This value is reflected by JavaScript’s target property, which belongs to the form object. The general syntax for referencing this property is:

formReference.target

This property can be both read and set at any time, even after the page has been laid out. Despite the fact that the TARGET attribute defaults to the current window or frame’s HTML document, the JavaScript’s target property does not default to any string.

The value of the JavaScript’s target property, like the HTML’s TARGET attribute, can be either a window or a frame name. In addition to these obvious values, there are several common references: _top, _parent, _self, and _blank. These values will be covered again when we discuss frames and windows and, for detailed information, you may also refer to HTML documentation. It may seem convenient to assign window or frame objects to this property, but unfortunately it only accepts HTML specifications.

Previous Table of Contents Next


With any suggestions or questions please feel free to contact us