|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
The ENCTYPE attribute was introduced by Netscape for the purpose of providing a file name to be uploaded as form input. You set ENCTYPE equal to the MIME type expected for the file being uploaded. ENCTYPE does not create the input field for the filename; rather, it gives the browser a cue as to what kind of file it is sending. When prompting for a file to upload, you need to use an <INPUT> tag with TYPE set equal to FILE. As an example of these three <FORM> tag attributes, examine the following HTML: <FORM ACTION=logo_upload.cgi METHOD=POST ENCTYPE=image/gif> Please enter the name of the GIF file containing your logo: <INPUT TYPE=FILE NAME=logo> <INPUT TYPE=SUBMIT VALUE=Upload> </FORM> The form header of this short form instructs the server to process the form data using the program named logo_upload.cgi. Form data is passed using the POST method, and the expected type of file being submitted is a GIF file. New <FORM> tag attributes in HTML 4.0 include TARGET, which is used to direct the response from the processing script to a particular frame; ACCEPT, which denotes the MIME types of files that the server processing the form can handle correctly (this is useful when a user is submitting a set of files to the server because you can then check to make sure that all the submitted files are of an acceptable MIME type); and ACCEPT-CHARSET, which specifies the character sets the server understands. Incorporating these attributes, the code above might look like this: <FORM ACTION=logo_upload.cgi METHOD=POST ENCTYPE=image/gif ACCEPT=image/gif,image/jpeg TARGET=main ACCEPT-CHARSET=EUC-JP> Please enter the name of the GIF file containing your logo: <INPUT TYPE=FILE NAME=logo> <INPUT TYPE=SUBMIT VALUE=Upload> </FORM> The EUC-JP value for the ACCEPT-CHARSET attribute suggests the use of a Japanese character set to the server that processes the form. The <FORM> tag can also take two event handlersonSubmit and onReset. This gives you the capability to execute some script code when the form is submitted or reset, respectively. If you write a JavaScript function that validates the data a user enters into a form, for example, you could invoke the script using an event handler as follows: <FORM ACTION=upload_logo.cgi onSubmit=validateform()> To learn more about using JavaScript to validate form input, see Using JavaScript to Create Smart Forms, p. 513. Named Input FieldsThe named input fields typically compose the bulk of a form. The fields appear as standard GUI controls, such as text boxes, check boxes, radio buttons, and menus. You assign each field a unique name that eventually becomes the variable name used in the processing script.
You can use different GUI controls to enter information into forms. The controls for named input fields appear in Table 8.2.
The <INPUT> TagYou might notice in Table 8.2 that the <INPUT> tag handles the majority of named input fields. <INPUT> is a standalone tag that, thanks to the many values of its TYPE attribute, can place most of the fields you need on your forms. <INPUT> also takes other attributes depending on which TYPE is in use. These additional attributes are covered for each type, as appropriate, over the next several sections.
Text and Password Fields Text and password fields are simple data entry fields. The only difference between them is that text typed into a password field appears onscreen as asterisks (*).
A text or password field is produced by the HTML (attributes in square brackets are optional): <INPUT TYPE={TEXT|PASSWORD} NAME=Name [VALUE=default_text] [SIZE=width] [MAXLENGTH=max_width]>
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |