input (type="file")NN 3 IE 4 DOM 1  

  

The fileUpload object is a form control generated with an input element whose type attribute is set to "file". The "fileUpload" term does not appear in scripts, but it is the way Netscape casually referred to this object when it was first scriptable.

To submit a file, the form element should have its method attribute set to POST and its enctype attribute set to multipart/form-data. But you also need some server programming to process the incoming data correctly.

 
HTML Equivalent
 
<input type="file">
 
Object Model Reference
 
[window.]document.formName.elementName
[window.]document.forms[i].elements[i]
[window.]document.getElementById("elementID")
 
Object-Specific Properties
 
acceptdefaultValueformnamesizetypevalue
 
Object-Specific Methods
 
handleEvent[ ]select( )
 
Object-Specific Event Handler Properties
 
HandlerNNIEDOM
onblur342
onchange342
onclick642
onfocus342
onkeydown64n/a
onkeypress64n/a
onkeyup64n/a
onmousedown642
onmousemove642
onmouseout642
onmouseover642
onmouseup642
onselect342
acceptNN 6 IE 4 DOM 1  

Read/Write  

Provides an optional advisory property consisting of a string of one or more comma-delimited MIME types of files that are being uploaded. Values have no impact on this element in current browsers.

 
Example
 
document.entryForm.myFileUpload.accept = "image/gif";
 
Value

String.

 
Default

None.

defaultValueNN 4 IE 4 DOM n/a  

Read/Write  

Returns the string assigned to the value attribute of the element in the source code (except in IE for Windows, which returns an empty string). A user must manually select a file for uploading, so pre-setting or attempting to alter this value is a waste of time.

 
Example
 
var initVal = document.entryForm.myFileUpload.defaultValue;
 
Value

String.

 
Default

None.

formNN 3 IE 4 DOM 1  

Read-only  

Returns a reference to the form element that contains the current element (if any). When processing an event from this element, the event handler function automatically has access to the input element (as the event object's target or srcElement property). By reading the form property, the script can easily access other controls within the same form.

 
Example
 
var theForm = evt.srcElement.form;
 
Value

form element object reference.

 
Default

None.

nameNN 2 IE 3 DOM 1  

Read/Write  

This is the identifier associated with the form control. The value of this property is submitted as one-half of the name/value pair when the form is submitted to the server. Names are hidden from user view, since control labels are assigned via other means, depending on the control type. Form control names may also be used by script references to the objects. Despite the modern standards' preference for the id attribute, many browsers still require that a form control be assigned a name attribute to allow the control's value to be submitted.

 
Example
 
document.orderForm.myFileChoice.name = "Win32File";
 
Value

Case-sensitive string identifier that follows the rules of identifier naming: it may contain no whitespace, cannot begin with a numeral, and should avoid punctuation except for the underscore character.

 
Default

None.

sizeNN 6 IE 4 DOM 1  

Read/Write  

Roughly speaking, indicates the width in characters that the input text box portion of the file input element should be sized to accommodate. In practice, the browser does not always accurately predict the proper width when the font used is a proportional one. See details in the size attribute discussion for the input element in Chapter 8. This property is not available for IE 4 on the Macintosh.

 
Example
 
document.forms[0].myFileUpload.size = 60;
 
Value

Integer.

 
Default

20

typeNN 3 IE 4 DOM 1  

Read-only  

Returns the type of form control element. The value is returned in all lowercase letters. It may be necessary to cycle through all form elements in search of specific types to do some processing on (e.g., emptying all form controls of type "text" while leaving other controls untouched).

 
Example
 
if (document.forms[0].elements[3].type == "file") {
    // process file input type here
}
 
Value

Any of the following constants (as a string): button | checkbox | file | hidden | image | password | radio | reset | select-multiple | select-one | submit | text | textarea.

 
Default

file

valueNN 2 IE 3 DOM 1  

Read-only  

Indicates the current value associated with the form control that is submitted with the name/value pair for the element. For a fileUpload object, this value is the URL-encoded full pathname to the local file. This is true even for the Macintosh browser versions, which tend to display only the file's name in the form element display. While the property accepts new value assignments in some browsers, only values assigned as a result of a user's explicit file menu choice get submitted.

 
Value

String.

 
Default

None.

handleEvent[ ]NN |4| IE n/a DOM n/a  

handleEvent(event)

  

Instructs the object to accept and process the event whose specifications are passed as the parameter to the method. The object must have an event handler for the event type to process the event. Navigator 4 only.

 
Parameters
 
  • A Navigator 4 event object.
 
Returned Value

None.

select( )NN 3 IE 4 DOM n/a  

  

Selects all the text displayed in the form element.

 
Parameters

None.

 
Returned Value

None.