The following methods are available in JavaScript:
abs acos alert anchor asin assign atan back big blink blur bold ceil charAt clear clearTimeout click close confirm cos eval exp fixed floor focus fontcolor fontsize forward getDate getDay getHours getMinutes getMonth getSeconds getTime getTimeZoneoffset getYear go indexOf italics lastIndexOf link log max min open parse pow prompt random round select setDate setHours setMinutes setMonth setSeconds setTimeout setTime setYear sin small sqrt strike sub submit substring sup tan toGMTString toLocaleString toLowerCase toString toUpperCase UTC write writeln
Displays an Alert dialog box with a message and an OK button.
Syntax
alert("message")
The argument message is any string.
Description
Use the alert method to display a message that does not require a user decision. The message argument specifies a message that the dialog box contains.
Applies to
window
Examples
In the following example, the testValue function checks the name entered by a user in the text element of a form to make sure that it is no more than eight characters in length. This example uses the alert method to prompt the user of an application to enter a valid value.
function testValue(textElement) {
if (textElement.length > 8) {
alert("Please enter a name that is 8 characters or less")
}
}
You can call the testValue function in the onBlur event handler of a form's text element, as shown in the following example:
Displays a Confirm dialog box with the specified message and OK and Cancel buttons.
Syntax
confirm("message")
The argument message is any string.
Description
Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. The message argument specifies a message that prompts the user for the decison. The confirm method returns true if the user chooses OK and false if the user chooses Cancel.
Applies to
window
Examples
This example uses the confirm method in the confirmCleanUp function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp() function closes the application.
function confirmCleanUp() {
if (confirm("Are you sure you want to quit this application?")) {
cleanUp()
}
}
You can call the confirmCleanUp function in the onClick event handler of a form's pushbutton, as shown in the following example:
For password, text, and textArea, gives focus to the object.
Syntax
focus()
Description
Use the focus method to navigate to a specific form element and give it focus. You can then either programatically enter a value in the element or let the user enter a value.
Applies to
password, text, textArea
Examples
In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the focus method returns focus to the password field and the select method highlights it so the user can re-enter the password.
function checkPassword(userPass) {
if (badPassword) {
alert("Please enter your password again.")
userPass.focus()
userPass.select()
}
}
This example assumes that the password is defined as:
Causes the calling string object to be displayed in the specified color by surrounding it with HTML font color tags, <FONTCOLOR=color>... <FONTCOLOR>
Syntax
fontcolor(color)
The argument to the method, color, must be a string containing a hashmark (#) followed by a triplet of hexadecimal number pairs. These three pairs represent the red, green, and blue values for the desired color, respectively.