Special Edition Using HTML 4: JavaScript Keyword Reference

By Rick Darnell

Properties

Properties are used to view or set the values of objects. An object is simply a vague generality until a property is used to define the values which make it specific.

action  The action property is a reflection of the action attribute in an HTML <form> tag, consisting of a destination URL for the submitted data. This value can be set or changed before or after the document has been loaded and formatted. In this example, the action for a form called outlineForm is set to the URL contained in the variable outlineURL.

outlineForm.action=outlineURL

Property of form.
See PROPERTIES encoding, method, target.

alinkColor  The color of a link after the mouse button is depressed--but before it's released--and expressed as a hexadecimal RGB triplet or string literal. It cannot be changed after the HTML source is processed. Both of these examples set the color to alice blue.

document.alinkColor="aliceblue"
document.alinkColor="F0F8FF"

Property of document.
See PROPERTIES bgColor, fgColor,
linkColor, vlinkColor.

anchors  An array of all defined anchors in the current document. If the length of an anchor array in a document is 5, then the anchors array is represented as document.anchors[0] through document.anchors[4].
Property of document.
See anchor OBJECT;
see PROPERTIES length and links.

appCodeName  Returns a read-only string with the code name of the browser.


document.write("The code name of your browser 
is " + navigator.appCodeName)

For most Netscape Navigator 2.0, this returns:

The code name of your browser 
is Mozilla

Property of navigator.
See PROPERTIES appName, appVersion,
userAgent.

appName  Returns a read-only string with the name of the browser.
Property of navigator.
See PROPERTIES appCodeName, appVersion,
userAgent.

appVersion  Returns a string with the version information of the browser in the format "releaseNumber (platform; country)." For a release of Netscape 2.0:

document.write(navigator.appVersion)

returns

2.0 (Win95; I)

This specifies Navigator 2.0 running on Windows 95 with an international release. The U country code specifies a US release, while an I indicates an international release.

Property of navigator.
See PROPERTIES appName, appCodeName,
userAgent.

bgColor  The document background color expressed as a hexadecimal RGB triplet or string literal. It can be reset at any time. Both of these examples set the background to alice blue.

document.bgColor = "aliceblue"
document.bgColor = "F0F8FF"

Property of document.
See PROPERTIES alinkColor, fgColor,
linkColor, vlinkColor.

checked  A Boolean value (true or false), indicating whether a check box or radio button is selected. The value is updated immediately when an item is checked. It's used in the following form:

formName.checkboxName.checked
formName.radioButtonName[index].checked

Property of checkbox and radio.
See defaultChecked PROPERTY.

cookie  String value of a small piece of information stored by Navigator in a client-side COOKIES.TXT file. The value stored in the cookie is found using substring charAt, IndexOf, and lastIndexOf. For more information, see the discussion under TERMS.

Property of document. See hidden OBJECT.

defaultChecked  A Boolean value (true or false) indicating whether a check box or radio button is checked by default. Setting a value to defaultChecked can override the checked attribute of a form element. The following section of code will reset a group of radio buttons to its original state by finding and setting the default button:


for (var i in menuForm.choices) 
{
   if (menuForm.choices[i].defaultChecked) 
{
      menuForm.choice[i].defaultChecked = true
   }
}

Property of checkbox and radio.
See form OBJECT;
see checked PROPERTY.

defaultSelected  A Boolean value (true or false) representing the default state of an item in a form select element. Setting a value with this property can override the selected attribute of an <option> tag. The syntax is identical to defaultChecked.
Property of options.
See PROPERTIES index, selected, selectedIndex.

defaultStatus  The default message displayed in the status bar at the bottom of a Navigator window when nothing else is displayed. This is preempted by a priority or transient message, such as a mouseOver event with an anchor. For example:

window.defaultStatus = 
"Welcome to my home page"

displays the welcome message while the mouse is not over a link, or Netscape is not performing an action that it needs to notify the user about.

Property of window.
See status PROPERTY.

defaultValue  The initial contents of hidden, password, text, textarea, and string form elements. For password elements, it is initially set to null for security reasons, regardless of any set value.
Property of hidden, password, text,
textarea.
See value PROPERTY.

E  The base of natural logarithms, also known as Euler's constant. The value is approximately 2.7182818285...
Property of Math.
See PROPERTIES LN2, LN10,
LOG2E, LOG10E, PI,
SQRT1_2, SQRT2.

elements  An array of objects containing form elements in HTML source order. The array index begins with zero and ends with the number of form elements -1. Property of form.
See elements OBJECT.

encoding  Returns a string reflecting the Mime encoding type, which is set in the enctype attribute of an HTML <form> tag.
Property of form.
See PROPERTIES action, method,
target.

fgColor  The color of foreground text represented as a hexadecimal RGB triplet or a string literal. This value cannot be changed after a document is processed. It can take two forms:

document.fgColor="aliceblue"
document.fgColor="F0F8FF"

Property of document.
See PROPERTIES alinkColor, bgColor,
linkColor, vlinkColor;
see fontcolor METHODS.

forms  An array of objects corresponding to named forms in HTML source order and containing an entry for each form object in a document. Property of document.
See form OBJECT;
see length PROPERTY.

frames  An array of objects corresponding to child frame windows created using the <frameset> tag. To obtain the number of child frames in a window, use the length property.
Property of window.
See frame OBJECT;
see length PROPERTY.

hash  Returns a string with the portion of a URL beginning with a hash mark (#), which denotes an anchor name fragment. It can be used to set a hash property, although it is safest to set the entire URL as a href property. An error is returned if the hash isn't found in the current location.
Property of link and location.
See anchor OBJECT;
see PROPERTIES host, hostname,
href, pathname, port,
protocol, search properties.

host  Returns a string formed by combining the hostname and port properties of a URL and provides a method for changing it.

location.host = "www.montna.com:80"

Property of link and location.
See PROPERTIES hash, hostname,
href, pathname, port,
protocol, search.

hostname  Returns or changes a string with the domain name or IP address of a URL. Property of link and location.
See PROPERTIES hash, host,
href, pathname, port,
protocol, search.

href  Returns a string with the entire URL. All other location and link properties are substrings of href, which can be changed at any time.
Property of link and location.
See PROPERTIES hash, host,
hostname, pathname, port,
protocol, search.

index  Returns the index of an option in a select element with zero being the first item. Property of options.
See PROPERTIES defaultSelected,
selected, selectedIndex.

lastModified  A read-only string containing the date that the current document was last changed, based on the file attributes. The string is formatted in the standard form used by JavaScript (see Date object). A common usage is:


document.write("This page last modified on 
" + document.lastModified)

Property of document.

length  An integer reflecting a length- or size-related property of an object.

Object Property Measured history Length of the history list

string Integer length of the string; zero for a null string

radio Number of radio buttons anchors, forms,
Number of elements in the array frames, links, options
Property of anchors, elements, forms,
frame, frames, history, links,
options, radio, string, window.

linkColor  The hyperlink color displayed in the document, expressed as a hexadecimal RGB triplet or as a string literal. It corresponds to the link attribute in the HTML <body> tag, and cannot be changed after the document is processed. Property of document. See PROPERTIES alinkColor, bgColor, fgColor, vlinkColor.

links  An array representing link objects defined in HTML using <a href=URL> tags with the first link identified as document.links[0]. See link object. See PROPERTIES anchors and length.

LN2  A constant representing the natural logarithm of 2 (approximately 0.693). Property of Math. See PROPERTIES E, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.

LN10  A constant representing the natural logarithm of 10 (approximately 2.302). Property of Math. See PROPERTIES E, LN2, LOG2E, LOG10E, PI, SQRT1_2, SQRT2.

location  Returns a string with the URL of the current document. This read-only property (document.location) is different from the location objects properties (window.location.propertyName), which can be changed. Property of document. See location OBJECT.

LOG2E  A constant representing the base 2 logarithm of e (approximately 1.442). Property of Math. See PROPERTIES E, LN2, LN10, LOG10E, PI, SQRT1_2, SQRT2.

LOG10E  A constant representing the base 10 logarithm of e (approximately .434). Property of Math. See PROPERTIES E, LN2, LN10, LOG2E, SQRT1_2, SQRT2.

method  Reflects the method attribute of an HTML <form> tag: either <GET> or <POST>. It can be set at any time. The first function returns the current value of the form object, while the second function sets the method to the contents of newMethod.

function getMethod(formObj) {
   return formObj.method
}
function setMethod(formObj,newMethod) {
   formObj.method = newMethod
}

Property of form.
See PROPERTIES action, encoding, target.

name  Returns a string with the name attribute of the object. This is the internal name for button, reset and submit objects, not the on-screen label. For example, after opening a new window with

indexOutline = window.open
("http://www.woss.com/outline.html","MenuPage")

and issuing the command document.write(indexOutline.name), JavaScript returns MenuPage, which was specified as the name attribute.

Property of button, checkbox, frame, password, radio, reset, select, submit, text, textarea, window. See value PROPERTY.

options  An array of option objects created by a select form element. The first option's index is zero, the second is 1, and so on. See select OBJECT.

parent  Refers to the calling document in the current frame created by a <frameset> tag. Using parent allows access to other frames created by the same <FRAMESET> tag. For example, two frames invoked are called index and contents. The index frame can write to the contents frame using the syntax:


parent.contents.document.write
	("Kilroy was here.")

Property of frame and window.

pathname  Returns the path portion from a URL. Although the pathname can be changed at any time, it is always safer to change the entire URL at once using the href property. Property of link and location. See PROPERTIES hash, host, hostname, href, port, protocol, search.

PI  Returns the value of pi (approximately 3.1415927). This is the ratio of the circumference of a circle to its diameter. Property of Math. See PROPERTIES E, LN2, LN10, LOG2E, LOG10E, SQRT1_2, SQRT2.

port  Returns the port number of a URL address, which is a substring of the host property in href. Property of link and location. See PROPERTIES hash, host, hostname, href, pathname, protocol, search.

protocol  Returns a string with the initial portion of the URL, up to and including the colon, which indicates the access method (http, ftp, mailto, and so on). Property of link and location.

See PROPERTIES hash, host, hostname, href, pathname, port, search.

referrer  Returns a read-only URL of the document that called the current document. In conjunction with a CGI script, it can be used to keep track of how users are linked to a page.


document.write("You came here from a page 
at " + document.referrer)

Property of document.

search  Returns a string containing any query information appended to a URL. Property of link and location. See PROPERTIES hash, host, hostname, href, pathname, port, protocol.

selected  Returns a Boolean value (true or false) indicating the current state of an option in a select object. The selected property can be changed at any time, and the display will immediately update to reflect the new value. The selected property is useful for select elements that are created by using the multiple attribute. Using this property, you can view or change the value of any element in an options array without changing the value of any other element in the array. Property of options. See PROPERTIES defaultSelected, index, selectedIndex.

selectedIndex  Returns an integer specifying the index of a selected item. The selectedIndex property is useful for select elements that are created without using the multiple attribute. If selectedIndex is evaluated when the multiple option is selected, the property returns the index of the first option only. Setting the property clears any other options that are selected in the element. Property of select, options. See PROPERTIES defaultSelected, index, selected.

self  Refers to the current window or form, and is useful for removing ambiguity when dealing with window and form properties with the same name. Property of frame and window. See window PROPERTY.

SQRT1_2  The square root of 1/2, also expressed as the inverse of the square root of 2 (approximately 0.707). Property of Math. See PROPERTIES E, LN2, LN10, LOG2E, LOG10E, PI, SQRT2.

SQRT2  The square root of 2 (approximately 1.414). Property of Math. See properties E, LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2.

status  Specifies a priority or transient message to display in the status bar at the bottom of the window, usually triggered by a mouseOver event from an anchor. To display when the mouse pointer is placed over a link, the usage is:


<A anchor definition 
onMouseOver="window.dstatus=`Your message.'; 
	return true">link</A>

Note the use of nested quotes and the required return true required for operation.

Property of window. See defaultStatus PROPERTY.

target  A string specifying the name of a window for responses to be posted to after a form is submitted. For a link, target returns a string specifying the name of the window that displays the content of a selected hypertext link.

homePage.target = 
"http://www.wossamatta.com/"

A literal must be used to set the target property. JavaScript expressions and variables are invalid entries.

Property of form, link, location. See PROPERTIES action, encoding, method.

text  Returns the value of text following the <option> tag in a select object. It can also be used to change the value of the option, with an important limitation: while the value is changed, its appearance on screen is not. Property of options.

title  Returns the read-only value set within HTML <title> tags. If a document doesn't include a title, the value is null. Property of document.

top  The topmost window, called an ancestor or Web browser window, that contains frames or nested framesets. Property of window.

userAgent  Header sent as part of HTTP protocol from client to server to identify the type of client. The syntax of the returned value is the same as appVersion. Property of navigator. See PROPERTIES appName, appVersion, appCodeName.

value  The value of an object depends on the type of object it is applied to.

Object Value Attribute button, reset, Value attribute that appears on submit screen, not the button name

checkbox On if item is selected, off if not

radio String reflection of value

hidden, text, Contents of the field textarea

select Reflection of option value password Return a valid default value, but an encrypted version if modified by the user Changing the value of a text or textarea object results in an immediate update to the screen. All other form objects are not graphically updated when changed.

Property of button, checkbox, hidden, options, password, radio, reset, submit, text, textarea.

For password, text, and textarea, see defaultValue PROPERTY.

For button, reset, and submit, see name PROPERTY.

For options, see PROPERTIES defaultSelected, selected, selectedIndex, text.

For checkbox and radio, see PROPERTIES checked and defaultChecked.

vlinkColor  Returns or sets the color of visited links using hexadecimal RGB triplets or a string literal. The property cannot be set after the document has been formatted. To override the browser defaults, color settings are used with the onLoad event handler in the <BODY> tag:


<BODY onLoad="document.vlinkColor=
`aliceblue'">

Property of document.
See PROPERTIES alinkColor, bgColor,
fgColor, linkColor.

window  A synonym for the current window to remove ambiguity between a window and form object of the same name. While it also applies to the current frame, it is less ambiguous to use the self property. Property of frame and window. See self PROPERTY.

© Copyright Macmillan Computer Publishing. All rights reserved.

Make a Comment

Loading Comments...

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
  •  
  •  
  •  
Thanks for your registration, follow us on our social networks to keep up-to-date