1. dateObjectName = new Date()To use Date methods:
2. dateObjectName = new Date("month day, year hours:minutes:seconds")
3. dateObjectName = new Date(year, month, day)
4. dateObjectName = new Date(year, month, day, hours, minutes, seconds)
dateObjectName.methodName(parameters)Exceptions: The Date object's parse and UTC methods are static methods that you use as follows:
Date.UTC(parameters)
Date.parse(parameters)
Property |
Description
prototype |
Lets you add a properties to a Date object. |
|
---|
Methods
The Date object has the following methods:
Event handlers
None. Built-in objects do not have event handlers.
Examples
The following examples show several ways to assign dates:
today = new Date()
birthday = new Date("December 17, 1995 03:24:00")
birthday = new Date(95,12,17)
birthday = new Date(95,12,17,3,24,0)
1. checkboxName.defaultChecked
2. radioName[index].defaultChecked
Implemented in
Navigator 2.0
Description
If a checkbox or radio button is selected by default, the value of the defaultChecked property is true; otherwise, it is false. defaultChecked initially reflects whether the CHECKED attribute is used within an <INPUT> tag; however, setting defaultChecked overrides the CHECKED attribute.
You can set the defaultChecked property at any time. The display of the checkbox or radio button does not update when you set the defaultChecked property, only when you set the checked property.
Examples
The following example resets an array of radio buttons called musicType on the musicForm form to the default selection state:
function radioResetter() {
var i=""
for (i in document.musicForm.musicType) {
if (document.musicForm.musicType[i].defaultChecked==true) {
document.musicForm.musicType[i].checked=true
}
}
} See also
checked property
selectName.options[index].defaultSelected
optionName.defaultSelected
Implemented in
Description
If an option in a Select object is selected by default, the value of the defaultSelected property is true; otherwise, it is false. defaultSelected initially reflects whether the SELECTED attribute is used within an <OPTION> tag; however, setting defaultSelected overrides the SELECTED attribute.
You can set the defaultSelected property at any time. The display of the Select object does not update when you set the defaultSelected property, only when you set the selected or selectedIndex properties.
A Select object created without the MULTIPLE attribute can have only one option selected by default. When you set defaultSelected in such an object, any previous default selections, including defaults set with the SELECTED attribute, are cleared. If you set defaultSelected in a Select object created with the MULTIPLE attribute, previous default selections are not affected.
Examples
In the following example, the restoreDefault function returns the musicType Select object to its default state. The for loop uses the options array to evaluate every option in the Select object. The if statement sets the selected property if defaultSelected is true.
function restoreDefault() {
The previous example assumes that the Select object is similar to the following:
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options[i].defaultSelected == true) {
document.musicForm.musicType.options[i].selected=true
}
}
}<SELECT NAME="musicType">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT> See also
index, selected, selectedIndex properties
windowReference.defaultStatus
Implemented in
Navigator 2.0
Description
The defaultStatus message appears when nothing else is in the status bar. Do not confuse the defaultStatus property with the status property. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor.
You can set the defaultStatus property at any time. You must return true if you want to set the defaultStatus property in the onMouseOver event handler.
Examples
In the following example, the statusSetter function sets both the status and defaultStatus properties in an onMouseOver event handler:
function statusSetter() {
In the previous example, notice that the onMouseOver event handler returns a value of true. You must return true to set status or defaultStatus in an event handler.
window.defaultStatus = "Click the link for the Netscape home page"
window.status = "Netscape home page"
}
<A HREF="http://www.netscape.com"
onMouseOver = "statusSetter(); return true">Netscape</A> See also
status property
1. passwordName.defaultValue
2. textName.defaultValue
3. textareaName.defaultValue
Implemented in
Navigator 2.0
Description
The initial value of defaultValue differs for each object:
function defaultGetter() {
msgWindow=window.open("")
msgWindow.document.write("hidden.defaultValue is " +
document.surfCity.hiddenObj.defaultValue + "<BR>")
msgWindow.document.write("password.defaultValue is " +
document.surfCity.passwordObj.defaultValue + "<BR>")
msgWindow.document.write("text.defaultValue is " +
document.surfCity.textObj.defaultValue + "<BR>")
msgWindow.document.write("textarea.defaultValue is " +
document.surfCity.textareaObj.defaultValue + "<BR>")
msgWindow.document.close()
}
1. navigator.mimeTypes[index1].description
2. navigator.plugins[index2].description
For Plugin objects: filename, length, name properties
<BODY
BACKGROUND="backgroundImage"
BGCOLOR="backgroundColor"
TEXT="foregroundColor"
LINK="unfollowedLinkColor"
ALINK="activatedLinkColor"
VLINK="followedLinkColor"
[onBlur="handlerText"]
[onFocus="handlerText"]
[onLoad="handlerText"]
[onUnload="handlerText"]>
</BODY>
Syntax
To use a document object's properties and methods:
1. document.propertyName
2. document.methodName(parameters) Parameters
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
Property of
window object
Implemented in
Description
An HTML document consists of <HEAD> and <BODY> tags. The <HEAD> tag includes information on the document's title and base (the absolute URL base to be used for relative URL links in the document). The <BODY> tag encloses the body of a document, which is defined by the current URL. The entire body of the document (all other HTML elements for the document) goes within the <BODY> tag.
You can load a new document by using the location object.
You can clear the document pane (and remove the text, form elements, and so on so they do not redisplay) by using document.close(); document.open(); document.write()
. You can omit the document.open()
call if you are writing text or HTML, since write does an implicit open of that mime type if the document stream is closed.
You can reference the anchors, forms, and links of a document by using the anchors, forms, and links arrays. These arrays contain an entry for each anchor, form, or link in a document.
Do not use location as a property of the document object; use the document.URL property instead. The document.location property, which is a synonym for document.URL, will be removed in a future release.
Properties
The document object has the following properties:
The following objects are also properties of the document object:
Methods
The document object has the following methods:
Event handlers
None. The onBlur, onFocus, onLoad, and onUnload event handlers are specified in the <BODY> tag but are actually event handlers for the window object.
Examples
The following example creates two frames, each with one document. The document in the first frame contains links to anchors in the document of the second frame. Each document defines its colors.
doc0.html
, which defines the frames, contains the following code:
<HTML>
<HEAD>
<TITLE>Document object example</TITLE>
</HEAD>
<FRAMESET COLS="30%,70%">
<FRAME SRC="doc1.html" NAME="frame1">
<FRAME SRC="doc2.html" NAME="frame2">
</FRAMESET>
</HTML>doc1.html
, which defines the content for the first frame, contains the following code:
<HTML>
<SCRIPT>
</SCRIPT>
<BODY
BGCOLOR="antiquewhite"
TEXT="darkviolet"
LINK="fuchsia"
ALINK="forestgreen"
VLINK="navy">
<P><B>Some links</B>
<LI><A HREF="doc2.html#numbers" TARGET="frame2">Numbers</A>
<LI><A HREF="doc2.html#colors" TARGET="frame2">Colors</A>
<LI><A HREF="doc2.html#musicTypes" TARGET="frame2">Music types</A>
<LI><A HREF="doc2.html#countries" TARGET="frame2">Countries</A>
</BODY>
</HTML>doc2.html
, which defines the content for the second frame, contains the following code:
<HTML>
<SCRIPT>
</SCRIPT>
<BODY
BGCOLOR="oldlace" onLoad="alert('Hello, World.')"
TEXT="navy">
<P><A NAME="numbers"><B>Some numbers</B></A>
<UL><LI>one
<LI>two
<LI>three
<LI>four</UL>
<P><A NAME="colors"><B>Some colors</B></A>
<UL><LI>red
<LI>orange
<LI>yellow
<LI>green</UL>
<P><A NAME="musicTypes"><B>Some music types</B></A>
<UL><LI>R&B
<LI>Jazz
<LI>Soul
<LI>Reggae</UL>
<P><A NAME="countries"><B>Some countries</B></A>
<UL><LI>Afghanistan
<LI>Brazil
<LI>Canada
<LI>Finland</UL>
</BODY>
</HTML> See also
Frame object, window object
Math.E
Implemented in
Navigator 2.0
Description
Because E is a constant, it is a read-only property of Math.
Examples
The following function returns Euler's constant:
function getEuler() {
return Math.E
} See also
LN2, LN10, LOG2E, LOG10E, PI, SQRT1_2, SQRT2 properties
1. formName.elements[index]
2. formName.elements.length
Implemented in
Navigator 2.0
Description
You can reference a form's elements in your code by using the elements array. This array contains an entry for each object (Button, Checkbox, FileUpload, Hidden, Password, Radio, Reset, Select, Submit, Text, or Textarea object) in a form in source order. For example, if a form has a text field and two checkboxes, these elements are reflected as formName.elements[0]
, formName.elements[1]
, and formName.elements[2]
.
Although you can also reference a form's elements by using the element's name (from the NAME attribute), the elements array provides a way to reference Form objects programmatically without using their names. For example, if the first object on the userInfo form is the userName Text object, you can evaluate it in either of the following ways:
userInfo.userName.value
To obtain the number of elements on a form, use the length property: formName
userInfo.elements[0].value.elements.length
. Each radio button in a Radio object appears as a separate element in the elements array.
Elements in the elements array are read-only. For example, the statement formName.elements[0]="music"
has no effect.
The value of each element in the elements array is the full HTML statement for the object.
Properties
The elements array has the following properties:
Property |
Description
length |
Reflects the number of elements in the form |
|
---|
Examples
See the examples for the Frame property.
navigator.mimeTypes[index].enabledPlugin
Implemented in
Navigator 3.0
Description
The enabledPlugin property is a string value.
Each Navigator plug-in may support multiple MIME types. Thus, each MIME type could potentially be supported by multiple plug-ins, helper applications, or by the Navigator itself. (On Macintosh and Unix, the user can configure the handler for each MIME type; on Windows, the handler is determined at Navigator start-up time.)
Without the enabledPlugin property, a script writer could determine if the user had a particular plug-in installed, and that their Navigator could handle a particular MIME type, but not if the MIME type was supported by a plug-in. The latter information is important because the script writer may want to dynamically emit an <EMBED> tag on the page if the user has a plug-in configured for the MIME type.
enabledPlugin is a read-only property.
Examples
The following example determines whether the Shockwave plug-in is installed. If it is, a movie is displayed.
// Can we display Shockwave movies?
See also the examples for the MimeType object.
mimetype = navigator.mimeTypes["application/x-director"]
if (mimetype) {
// Yes, so can we display with a plug-in?
plugin = mimetype.enabledPlugin
if (plugin)
// Yes, so show the data in-line
document.writeln("Here's a movie: <EMBED SRC=mymovie.dir HEIGHT=100 WIDTH=100>")
else
// No, so provide a link to the data
document.writeln("<A HREF='mymovie.dir>Click here</A> to see a movie.")
} else {
// No, so tell them so
document.writeln("Sorry, can't show you this cool movie.")
} See also
description, type, suffixes properties
formName.encoding
Implemented in
Navigator 2.0
Description
The encoding property initially reflects the ENCTYPE attribute of the <FORM> tag; however, setting encoding overrides the ENCTYPE attribute.
You can set the encoding property at any time.
Examples
The following function returns the value of the musicForm encoding property:
function getEncoding() {
return document.musicForm.encoding
} See also
action, method, target properties; Form object
escape("string")
escape("&")The following example returns "%21%23":
escape("!#")
eval(string)
"3 * x + 2"
, to a variable, and then calling eval at a later point in your script.
document.write
. In LiveWire, you can display the same output by calling the write function instead of using document.write
.
Example 1. Both of the write statements below display 42. The first evaluates the string "x + y + 1," and the second evaluates the string "42."
var x = 2Example 2. In the following example, the getFieldName(n) function returns the name of the nth form element as a string. The first statement assigns the string value of the third form element to the variable field. The second statement uses eval to display the value of the form element.
var y = 39
var z = "42"
document.write(eval("x + y + 1"), "<BR>")
document.write(eval(z), "<BR>")
var field = getFieldName(3)Example 3. The following example uses eval to evaluate the string str. This string consists of JavaScript statements that open an Alert dialog box and assigns z a value of forty-two if x is five, and assigns zero to z otherwise. When the second statement is executed, eval will cause these statements to be performed, and it will also evaluate the set of statements and return the value that is assigned to z.
document.write("The field named ", field, " has value of ", eval(field + ".value"))
var str = "if (x == 5) {alert('z is 42'); z = 42;} else z = 0; "Example 4. In the following example, the setValue function uses eval to assign the value of the variable newValue to the text field textObject:
document.write("<P>z is ", eval(str))
function setValue (textObject, newValue) {
eval ("document.forms[0]." + textObject + ".value") = newValue
}
Math.exp(number)
Implemented in
Navigator 2.0
Examples
The following function returns the exp value of the variable x:
function getExp(x) {
If you pass getExp the value 1, it returns 2.718281828459045.
return Math.exp(x)
} See also
log, pow methods