DekGenius.com
Team LiB   Previous Section   Next Section
FileUpload a file upload field for form input

Availability

JavaScript 1.0 Inherits from Input, HTMLElement

Synopsis

form.name
form.elements[i]

Properties

FileUpload inherits properties from Input and HTMLElement and defines or overrides the following:

value [ JavaScript 1.1]

A read-only string that specifies the filename entered by the user into the FileUpload object. The user may enter a filename either by typing it directly or by using the directory browser associated with the FileUpload object.

To prevent malicious programs from uploading arbitrary files from the client, this property may not be set by JavaScript code. Similarly, the value attribute of the <input> tag does not specify the initial value for this property.

Methods

FileUpload inherits methods from Input and HTMLElement.

Event Handlers

FileUpload inherits event handlers from Input and HTMLElement and defines or overrides the following:

onchange

Invoked when the user changes the value in the FileUpload element and moves the keyboard focus elsewhere. This event handler is not invoked for every keystroke in the FileUpload element, but only when the user completes an edit.

HTML Syntax

A FileUpload element is created with a standard HTML <input> tag:

<form enctype="multipart/form-data"
      method="post">         // Required attributes
    ...
  <input
    type="file"              // Specifies that this is a FileUpload element
    [ name="name" ]          // A name you can use later to refer to this element
                             // Specifies the name property
    [ size="integer" ]       // How many characters wide the element is
    [ maxlength="integer" ]  // Maximum allowed number of input characters
    [ onblur="handler" ]     // The onblur(  ) event handler
    [ onchange="handler" ]   // The onchange(  ) event handler
    [ onfocus="handler" ]    // The onfocus(  ) event handler
  >
    ...

Description

The FileUpload element represents a file upload input element in a form. In many respects, this input element is much like the Text element. On the screen, it appears like a text input field with the addition of a Browse button that opens a directory browser. Entering a filename into a FileUpload element (either directly or through the browser) causes Netscape to submit the contents of that file along with the form. For this to work, the form must use "multipart/form-data" encoding and the POST method.

The FileUpload element does not have a defaultValue property and does not recognize the value HTML attribute to specify an initial value for the input field. Similarly, the value property of the FileUpload element is read-only. Only the user may enter a filename; JavaScript may not enter text into the FileUpload field in any way. This is to prevent malicious JavaScript programs from uploading arbitrary files (such as password files) from the user's machine.

See Also

Form, HTMLElement, Input, Text; HTMLInputElement in the DOM reference section

    Team LiB   Previous Section   Next Section