Understanding JavaScript objects - Online JavaScript help
Sponsored Links
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.
![]()
- How do you set the URL of an image called myphoto?
- How would you specify the value of a text field named yourname contained in contactform form?
Click this button if you liked the article!
Page contents:
Comments, questions, feedback... whatever!
Recent Articles
Recent Blog Posts
Popular Articles
- Hotmail Sign In page
- Create a Hotmail account - Instructions
- Create Gmail address
- Download and install Outlook Express
- Get your free Gmail address
- Outlook Express new version
- Create my own email address
- Browers for Windows list
- Get email address
- Color combinations for web sites and pages
- Create Yahoo ID
