Exforsys

H I D E

Home arrow Technical Training arrow JavaScript Tutorial

JavaScript FileUpload Object

Author : Exforsys Inc.     Published on: 18th May 2007

JavaScript FileUpload object

In this JavaScript tutorial, you will learn about FileUpload object, FileUpload properties, accessKey, disabled, form, name, type, value, FileUpload methods - blur(), focus(), select(), handleEvent(), click() and event handlers - onblur, onchange and onfocus.


FileUpload object:

FileUpload represents an element that allows a user to specify a file to be uploaded or submitted along with the form. The FileUpload object is a Browser object and is used to access the above FileUpload element of a form. Thus, the FileUpload object allows the user to give any file as input. If a user wants to access the FileUpload object then he or she can using the indexing concept on the elements array. The user can make use of each element inside the form that is stored as an array element within the array named elements [].

To implement the FileUpload object:


<
FORM>
<
INPUT TYPE="file" NAME="elementName">
FORM>

The above gives a text area and a Browse button where users can upload their files of choice to the form.

Properties of FileUpload object:

  • accessKey
  • disabled
  • form
  • name
  • type
  • value

accessKey:

The accessKey property of FileUpload object is used to set or return the accessKey for the field. The returned value from this property is a string.

disabled:

The disabled property of FileUpload object is used to set or return whether or not the field is disabled. The returned value from this property would be a boolean type that is true or false.

form:

The FileUpload object is a Browser object, used to access the FileUpload element of a form. The form property of FileUpload object is used to reference the form that contains the file upload field. Thus, the form property of FileUpload object returns a reference to the parent form of the FileUpload object.

General syntax of form property of FileUpload object is:


object.form

name:

The name property of FileUpload object denotes the name of the FileUpload field.

General syntax of name property of FileUpload object is:


object.name

type:

The type of the calling form element and the type property of FileUpload object denotes the file type.

General syntax of type property of FileUpload object is:


object.type

value:

The value property of FileUpload object denotes the file name entered into the FileUpload field.

NOTE: FileUpload object is a read only property.

General syntax of form property of FileUpload object is:


object.value

Methods of FileUpload object:

  • blur()
  • focus()
  • select()
  • handleEvent()
  • click()

blur():

The blur() method of FileUpload object is used to remove the focus away from the FileUpload field.

General syntax for using this method is:


object.blur()

focus():

The focus() method of FileUpload object is used to set the focus on the FileUpload field.

General syntax for using this method is:


object.focus()

select():

The select() method of FileUpload object is used for selecting the input area of the FileUpload field.

General syntax for using select() method is:


object.select()

handleEvent():

The handleEvent() method of FileUpload object is used to call or invoke the handler for the specified event.

General syntax for using this method is:


handleEvent(event)

In the above statement, the event given in argument of the handleEvent method denotes the name of the event associated with the object that has the event handler.

click():

The click() method of FileUpload object denotes and simulates the mouse-click on the FileUpload object.

General syntax for using click() method is:


object.click()

Event Handlers of FileUpload object:

  • onBlur
  • onChange
  • onFocus

onBlur:

The onBlur Event Handlers of FileUpload object fire and execute on the occurrence of the blur event. The onBlur Event Handlers of FileUpload object fire and execute JavaScript code when the focus is lost from the fileUpload field.

Ads

onChange:

The onChange Event Handlers of FileUpload object fire and execute JavaScript code when the user changes the value of the FileUpload field and moves focus away from the field.

onFocus:

The onFocus Event Handlers of FileUpload object fire and execute on the occurrence of the focus event. The onFocus Event Handlers of FileUpload object (in contrast to OnBlur event handler) fire and execute JavaScript code when the focus is set on the FileUpload field.



Read Next: JavaScript Form Object


 
This tutorial is part of a JavaScript Tutorial tutorial series. Read it from the beginning and learn yourself.

JavaScript Tutorial

  1. JavaScript Browser Objects Part 2
  2. JavaScript Frame object
  3. JavaScript Form Object
  4. JavaScript FileUpload Object
  5. JavaScript Event Object Properties and Methods
  6. JavaScript Event Object
  7. JavaScript Elements and Embed Objects
  8. JavaScript Applet Objects
  9. JavaScript Browser Objects
  10. JavaScript Object Oriented Features
  11. JavaScript Window Object Open Method Part 2
  12. JavaScript Window Object Open Method
  13. JavaScript Window Object Timeout Methods
  14. JavaScript Location Object
  15. JavaScript Location Object Properties
  16. JavaScript History Object Properties and Methods
  17. JavaScript Document Object Methods Part II
  18. JavaScript Document Object Methods Part I
  19. JavaScript Document Object Properties
  20. JavaScript Document Object
  21. JavaScript Windows Object Properties Part II
  22. JavaScript Windows Object Properties Part I
  23. JavaScript DOM Window Object
  24. Working with JavaScript DOM Objects
  25. JavaScript Array Object Methods – Part II
  26. JavaScript Array Object
  27. JavaScript Array Object Methods – Part I
  28. JavaScript Boolean Object
  29. JavaScript OnError Event
  30. JavaScript Exception Handling – Part II
  31. JavaScript Exception Handling – Part I
  32. JavaScript Event Handler
  33. JavaScript Events Handling
  34. JavaScript Array Operations
  35. JavaScript Two Dimensional Arrays
  36. Passing values to JavaScript Function
  37. JavaScript Functions
  38. JavaScript Arrays
  39. JavaScript Iterative Structures - Part II
  40. JavaScript Iterative Structures - Part I
  41. JavaScript Math Object
  42. JavaScript Date Object
  43. JavaScript String Object
  44. JavaScript Objects
  45. JavaScript Confirm Box
  46. JavaScript Alert Box
  47. JavaScript Conditional Statements Part 2
  48. JavaScript Conditional Statements Part 1
  49. How to use JavaScript in HTML page
  50. JavaScript Variables
  51. JavaScript Features
  52. JavaScript Introduction
 

Comments