Lets you work with dates and times.
To create a Date object:
1. dateObjectName = new Date() 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 is either the name of a new object or a property of an existing object.
To use Date methods:
dateObjectName.methodName(parameters)dateObjectName is either the name of an existing Date object or a property of an existing object..
Exceptions: The Date object's parse and UTC methods are static methods that you use as follows:
Date.UTC(parameters) Date.parse(parameters)
The Date object is a built-in JavaScript object.
Form 1 of the syntax creates today's date and time. If you omit hours, minutes, or seconds from form 2 or 4 of the syntax, the value will be set to zero.
The way JavaScript handles dates is very similar to the way Java handles dates: both languages have many of the same date methods, and both store dates internally as the number of milliseconds since January 1, 1970 00:00:00. Dates prior to 1970 are not allowed.
A Boolean value indicating the default selection state of a checkbox or radio button.
1. checkboxName.defaultChecked 2. radioName[index].defaultChecked
checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.
radioName is the value of the NAME attribute of a radio object.
index is an integer representing a radio button in a radio object.
If an 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.
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 } } }
A Boolean value indicating the default selection state of an option in a select object.
selectName.options[index].defaultSelected
selectName is either the value of the NAME attribute of a select object or an element in the elements array.
index is an integer representing an option in a select object.
options array
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.
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() { 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 } } }The previous example assumes that the select object is similar to the following:
<SELECT NAME="musicType"> <OPTION SELECTED> R&B <OPTION> Jazz <OPTION> Blues <OPTION> New Age </SELECT>
The default message displayed in the status bar at the bottom of the window.
windowReference.defaultStatus
windowReference is a valid way of referring to a window, as described in the window object.
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.
In the following example, the statusSetter() function sets both the status and defaultStatus properties in an onMouseOver event handler:
function statusSetter() { 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>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.
A string indicating the default value of a password, text, or textarea object.
1. passwordName.defaultValue 2. textName.defaultValue 3. textareaName.defaultValue
passwordName is either the value of the NAME attribute of a password object or an element in the elements array.
textName is either the value of the NAME attribute of a text object or an element in the elements array.
textareaName is either the value of the NAME attribute of a textarea object or an element in the elements array.
The initial value of defaultValue differs for each object:
Setting defaultValue programatically overrides the initial setting. If you programatically set defaultValue for the password object and then evaluate it, JavaScript returns the current value.
You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property.
The following function evaluates the defaultValue property of objects on the surfCity form and displays the values in the msgWindow window:
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() }
Contains information on the current document, and provides methods for displaying HTML output to the user.
To define a document object, use standard HTML syntax:
<BODY BACKGROUND="backgroundImage" BGCOLOR="backgroundColor" TEXT="foregroundColor" LINK="unfollowedLinkColor" ALINK="activatedLinkColor" VLINK="followedLinkColor" [onLoad="handlerText"] [onUnload="handlerText"]> </BODY>BACKGROUND specifies an image that fills the background of the document.
To use a document object's properties and methods:
1. document.propertyName 2. document.methodName(parameters)propertyName is one of the properties listed below.
An HTML document consists of a <HEAD> and <BODY> tag. The <HEAD> 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 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.
The following objects are also properties of the document object:
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:
DOC1.HTML, which defines the content for the first frame, contains the following code:
Some links
DOC2.HTML, which defines the content for the second frame, contains the following code:
Euler's constant and the base of natural logarithms, approximately 2.718.
Math.E
Because E is a constant, it is a read-only property of Math.
The following example displays Euler's constant:
document.write("Euler's constant is " + Math.E)
An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order.
1. formName.elements[index] 2. formName.elements.length
formName is either the name of a form or an element in the forms array.
index is an integer representing an object on a form.
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, 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 programatically 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 userInfo.elements[0].value
To obtain the number of elements on a form, use the length property: formName.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.
See the examples for the name property.
An array of objects corresponding to form elements (such as checkbox, radio, and text objects) in source order. See elements array.
A string specifying the MIME encoding of the form.
formName.encoding
formName is either the name of a form or an element in the forms array.
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.
Certain values of the encoding property may require specific values for other form properties. See RFC 1867 for more information.
The following function returns the value of the musicForm encoding property:
function getEncoding() { return document.musicForm.encoding }
Returns the ASCII encoding of an argument in the ISO Latin-1 character set.
escape("string")
string is a non-alphanumeric string in the ISO Latin-1 character set, or a property of an existing object.
The escape function is not a method associated with any object, but is part of the language itself.
The value returned by the escape function is a string of the form "%xx", where xx is the ASCII encoding of a character in the argument. If you pass the escape function an alphanumeric character, the escape function returns the same character.
The following example returns "%26"
escape("&")
The following example returns "%21%23"
escape("!#")
The eval function evaluates a string and returns a value.
eval(string)string is any string representing a JavaScript expression, statement, or sequence of statements. The expression can include variables and properties of existing objects.
The eval function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself.
The argument of the eval function is a string. Do not call eval to evaluate an arithmetic expression. JavaScript evaluates arithmetic expressions automatically. If the argument represents an expression, eval evaluates the expression. If the argument represents one or more JavaScript statements, eval performs the statements.
If you construct an arithmetic expression as a string, you can use eval to evaluate it at a later time. For example, suppose you have a variable x. You can postpone evaluation of an expression involving x by assigning the string value of the expression, say "3 * x + 2", to a variable, and then calling eval at a later point in your script.
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 = 2 var y = 39 var z = "42" document.write(eval("x + y + 1"), "<BR>") document.write(eval(z), "<BR>")
Example 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 field = getFieldName(3) document.write("The field named ", field, " has value of ", eval(field + ".value"))
Example 3. The following example uses eval to evaluate the string str. This string consists of JavaScript statements that opens an alert dialog box and assigns z a value of 42 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.
var str = "if (x == 5) {alert('z is 42'); z = 42;} else z = 0; " document.write("<P>z is ", eval(str))
Example 4. In the following example, the setValue() function uses eval to assign the value of the variable newValue to the text field textObject.
function setValue (textObject, newValue) { eval ("document.forms[0]." + textObject + ".value") = newValue }
Returns enumber, where number is the argument, and e is Euler's constant, the base of the natural logarithms.
Math.exp(number)number is any numeric expression or a property of an existing object.
//Displays the value 2.718281828459045 document.write("The value of e<SUP>1</SUP> is " + Math.exp(1))