Javascript objects and properties - online javascript help - javascript help tutorial

Sponsored Links

Understanding JavaScript objects - Online JavaScript help

Okay, so we learnt that JavaScript uses a heirarchical dot notation to refer to objects. In addition to the name property, objects can have other properties.
For example, an image located in a document is an object and has the following properties:

  • border: value of <IMG> BORDER attribute
  • height: value of HEIGHT attribute
  • width: value of WIDTH attribute
  • src: the URL of the image
  • hspace: value of HSPACE attribute
  • vspace: value of VSPACE attribute
  • complete: determines whether the image has been completely loaded
  • lowsrc: the URL of lower quality image specified through LOWSRC attribute
  • name: the value of NAME attribute (Just to clarify... the name of an image refers to the HTML name attribute and NOT the file name. By the by, you can use the same value in the NAME attribute value and file name.)

To refer to the source of an image named logo we use:
document.logo.src

Similarly, its width is refered as:
document.logo.width

Different HTML elements have different properties. For example, a text field form object has the following properties:

  • name: specifies the text field name
  • value: specifies its value (the text contained in the field)
  • defaultValue: determines the default text value
  • type: identifies its type

To set the value of a text field, we use the = (equal too) operator as:

document.contactform.add.value = "Type your address here";

This is a JavaScript statement that instructs the browser to displays the text Type your address here in the text field add.

Assignments

  1. How do you set the URL of an image called myphoto?
  2. How would you specify the value of a text field named yourname contained in contactform form?

Click here for possible answers



Page contents: Javascript objects and properties - online javascript help - javascript help tutorial

AddThis Social Bookmark Button

JavaScript Tutorial