Property. A string specifying the color of the document (foreground) text.
document.fgColor
The fgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in "Color values". This property is the JavaScript reflection of the TEXT attribute of the <BODY> tag. The default value of this property is set by the user on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu. You cannot set this property after the HTML source has been through layout.
You can override the value set in the fgColor property in either of the following ways:
The following example sets the color of the foreground text to aqua using a string literal:
document.fgColor="aqua"
The following example sets the color of the foreground text to aqua using a hexadecimal triplet:
document.fgColor="00FFFF"
alinkColor, bgColor, linkColor, vlinkColor properties; fontcolor method
Property. The name of a plug-in file on disk.
1. navigator.plugins[index].filename
2. navigator.plugins[pluginName].filename
filename is a read-only property.
See the examples for the Plugin object.
description, length, name properties
<INPUT
TYPE="file"
NAME="fileUploadName"
[onBlur="handlerText"]
[onChange="handlerText"]
[onFocus="handlerText"]
>
To use a FileUpload object's properties and methods:
fileUploadName.propertyName
fileUploadName.methodName
fileUploadName is the value of the NAME attribute of a FileUpload object.
propertyName is one of the properties listed below.
methodName is one of the properties listed below.
A FileUpload object on a form looks as follows:
A FileUpload object is a form element and must be defined within a <FORM> tag.
The FileUpload object has the following properties:
The FileUpload object has the following methods:
<FORM NAME="form1">
File to send: <INPUT TYPE="file" NAME="myUploadObject">
<P>Get properties<BR>
<INPUT TYPE="button" VALUE="name"
onClick="alert('name: ' + document.form1.myUploadObject.name)">
<INPUT TYPE="button" VALUE="value"
onClick="alert('value: ' + document.form1.myUploadObject.value)"><BR>
</FORM>
Method. Causes a string to be displayed in fixed-pitch font as if it were in a <TT> tag.
stringName.fixed()
stringName is any string or a property of an existing object.
Use the fixed method with the write or writeln methods to format and display a string in a document.
The following example uses the fixed method to change the formatting of a string:
var worldString="Hello, world"
document.write(worldString.fixed())
The previous example produces the same output as the following HTML:
<TT>Hello, world</TT>
Method. Returns the greatest integer less than or equal to a number.
Math.floor(number)
number is any numeric expression or a property of an existing object.
The following function returns the floor value of the variable x:
function getFloor(x) {
return Math.floor(x)
}
ceil method
Method. Gives focus to the specified object.
1. fileUploadName.focus()
2. passwordName.focus()
3. selectName.focus()
4. textName.focus()
5. textareaName.focus()
6. frameReference.focus()
7. windowReference.focus()
frameReference is a valid way of referring to a frame, as described in the Frame object.
windowReference is a valid way of referring to a window, as described in the window object.
Button object, Checkbox object, FileUpload object, Frame object, Password object, Radio object, Reset object object, Select object, Submit object, Text object, Textarea object, window object
Note
On some platforms, the focus method gives focus to a frame but the focus is not visually apparent (for example, the frame's border is not darkened). Please see the release notes (after starting Netscape, choose Release Notes from the Help menu).
function checkPassword(userPass) {
if (badPassword) {
alert("Please enter your password again.")
userPass.focus()
userPass.select()
}
}
This example assumes that the Password object is defined as
<INPUT TYPE="password" NAME="userPass">
blur method, select method
stringName.fontcolor(color)
stringName is any string or a property of an existing object.
color is a string or a property of an existing object, expressing the color as a hexadecimal RGB triplet or as one of the string literals listed in "Color values".
The fontcolor method overrides a value set in the fgColor property.
The following example uses the fontcolor method to change the color of a string:
var worldString="Hello, world"
document.write(worldString.fontcolor("maroon") +
" is maroon in this line")
document.write("<P>" + worldString.fontcolor("salmon") +
" is salmon in this line")
document.write("<P>" + worldString.fontcolor("red") +
" is red in this line")
document.write("<P>" + worldString.fontcolor("8000") +
" is maroon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FA8072") +
" is salmon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FF00") +
" is red in hexadecimal in this line")
The previous example produces the same output as the following HTML:
<FONT COLOR="maroon">Hello, world</FONT> is maroon in this line
<P><FONT COLOR="salmon">Hello, world</FONT> is salmon in this line
<P><FONT COLOR="red">Hello, world</FONT> is red in this line
<FONT COLOR="8000">Hello, world</FONT> is maroon in hexadecimal in this line
<P><FONT COLOR="FA8072">Hello, world</FONT> is salmon in hexadecimal in this line
<P><FONT COLOR="FF00">Hello, world</FONT> is red in hexadecimal in this line
stringName.fontsize(size)
stringName is any string or a property of an existing object.
The following example uses string methods to change the size of a string:
var worldString="Hello, world"
document.write(worldString.small())
document.write("<P>" + worldString.big())
document.write("<P>" + worldString.fontsize(7))
The previous example produces the same output as the following HTML:
<SMALL>Hello, world</SMALL>
<P><BIG>Hello, world</BIG>
<P><FONTSIZE=7>Hello, world</FONTSIZE>
To define a form, use standard HTML syntax with the addition of JavaScript event handlers:
<FORM
NAME="formName"
TARGET="windowName"
ACTION="serverURL"
METHOD=GET | POST
ENCTYPE="encodingType"
[onReset="handlerText"]
[onSubmit="handlerText"]>
</FORM>
ACTION="serverURL" specifies the URL of the server to which form field input information is sent. This attribute can specify a CGI or LiveWire application on the server; it can also be a mailto: URL if the form is to be mailed. See the location object for a description of the URL components. You can access this value using the action property.
To use a Form object's properties and methods:
1. formName.propertyName
2. formName.methodName(parameters)
3. forms[index].propertyName
4. forms[index].methodName(parameters)
formName is the value of the NAME attribute of a Form object.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
Each form in a document is a distinct object.
You can reference a form's elements in your code by using the element's name (from the NAME attribute) or the elements array. The elements array contains an entry for each element (such as a Checkbox, Radio, or Text object) in a form.
1. document.forms[index]
2. document.forms.length
To obtain the number of forms in a document, use the
length property: document.forms.length
.
The Form object has the following properties:
The following objects are also properties of the Form object:
The forms array has the following properties:
Property | Description |
---|---|
length |
Reflects the number of forms in the document |
The Form object has the following methods:
eval method |
toString method valueOf method |
<HTML>
<HEAD>
<TITLE>Form object example</TITLE>
</HEAD>
<SCRIPT>
function setCase (caseSpec){
if (caseSpec == "upper") {
document.form1.firstName.value=document.form1.firstName.value.toUpperCase()
document.form1.lastName.value=document.form1.lastName.value.toUpperCase()}
else {
document.form1.firstName.value=document.form1.firstName.value.toLowerCase()
document.form1.lastName.value=document.form1.lastName.value.toLowerCase()}
}
</SCRIPT>
<BODY>
<FORM NAME="form1">
<B>First name:</B>
<INPUT TYPE="text" NAME="firstName" SIZE=20>
<BR><B>Last name:</B>
<INPUT TYPE="text" NAME="lastName" SIZE=20>
<P><INPUT TYPE="button" VALUE="Names to uppercase" NAME="upperButton"
onClick="setCase('upper')">
<INPUT TYPE="button" VALUE="Names to lowercase" NAME="lowerButton"
onClick="setCase('lower')">
</FORM>
</BODY>
</HTML>
<BODY onLoad="alert('You are looking at the ' + document.forms[0] + ' form!')">
If the form name is musicType, the alert displays the following message:
You are looking at the <object musicType> form!
<HTML>
<HEAD>
<TITLE>Form object/onSubmit event handler example</TITLE>
<TITLE>Form object example</TITLE>
</HEAD>
<SCRIPT>
var dataOK=false
function checkData (){
if (document.form1.threeChar.value.length == 3) {
return true}
else {
alert("Enter exactly three characters. " + document.form1.threeChar.value +
" is not valid.")
return false}
}
</SCRIPT>
<BODY>
<FORM NAME="form1" onSubmit="return checkData()">
<B>Enter 3 characters:</B>
<INPUT TYPE="text" NAME="threeChar" SIZE=3>
<P><INPUT TYPE="submit" VALUE="Done" NAME="submit1"
onClick="document.form1.threeChar.value=document.form1.threeChar.value.toUpperCase()">
</FORM>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Form object/submit method example</TITLE>
</HEAD>
<SCRIPT>
var dataOK=false
function checkData (){
if (document.form1.threeChar.value.length == 3) {
document.form1.submit()}
else {
alert("Enter exactly three characters. " + document.form1.threeChar.value +
" is not valid.")
return false}
}
</SCRIPT>
<BODY>
<FORM NAME="form1" onSubmit="alert('Form is being submitted.')">
<B>Enter 3 characters:</B>
<INPUT TYPE="text" NAME="threeChar" SIZE=3>
<P><INPUT TYPE="button" VALUE="Done" NAME="button1"
onClick="checkData()">
</FORM>
</BODY>
</HTML>
Button object, Checkbox object, FileUpload object, Hidden object, Password object, Radio object, Reset object, Select object, Submit object, Text object, Textarea object; form property
Property. An object reference specifying the form containing an object.
this.form
objectReference.form
objectReference specifies an object on a form.
Button object, Checkbox object, FileUpload object, Hidden object, Password object, Radio object, Reset object, Select object, Submit object, Text object, Textarea object
<FORM NAME="myForm">
Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga">
<P>
<INPUT NAME="button1" TYPE="button" VALUE="Show Form Name"
onClick="this.form.text1.value=this.form.name">
</FORM>
function showElements(theForm) {
str = "Form Elements of form " + theForm.name + ": \n "
for (i = 0; i < theForm.length; i++)
str += theForm.elements[i].name + "\n"
alert(str)
}
</script>
<FORM NAME="myForm">
Form name:<INPUT TYPE="text" NAME="text1" VALUE="Beluga">
<P>
<INPUT NAME="button1" TYPE="button" VALUE="Show Form Name"
onClick="this.form.text1.value=this.form.name">
<INPUT NAME="button2" TYPE="button" VALUE="Show Form Elements"
onClick="showElements(this.form)">
</FORM>
The alert dialog box displays the following text:
JavaScript Alert:
Form Elements of form myForm:
text1
button1
button2
document.myForm.myTextObject.form
Property. An array of objects corresponding to the forms (<FORM> tags) in a document in source order. See the Form object for information.
Method. Loads the next URL in the history list.
history.forward()
The following custom buttons perform the same operations as the Navigator Back and Forward buttons:
<P><INPUT TYPE="button" VALUE="< Back"
onClick="history.back()">
<P><INPUT TYPE="button" VALUE="> Forward"
onClick="history.forward()">
To define a Frame object, use standard HTML syntax with the addition of JavaScript event handlers:
<FRAMESET
ROWS="rowHeightList"
COLS="columnWidthList"
[onBlur="handlerText"]
[onFocus="handlerText"]
[onLoad="handlerText"]
[onUnload="handlerText"]>
<FRAME SRC="URL" NAME="frameName">
[ ... <FRAME SRC="URL" NAME="frameName">]
</FRAMESET>
SRC="URL" specifies the URL of the document to be
displayed in the frame. The URL cannot include an anchor name; for example
<FRAME SRC="doc2.html#colors" NAME="frame2">
is invalid.
See the location object for a description
of the URL components.
To use a Frame object's properties:
1. [windowReference.]frameName.propertyName
2. [windowReference.]frames[index].propertyName
3. window.propertyName
4. self.propertyName
5. parent.propertyName
1. frameReference.onblur=errorHandler
2. frameReference.onfocus=errorHandler
windowReference is a variable windowVar from a window definition (see the window object), or one of the synonyms top or parent.
frameName is the value of the NAME attribute in the <FRAME> tag of a Frame object.
propertyName is one of the properties listed below.
frameReference is a valid way of referring to a frame.
The Frame object is a property of the window object.
The frames array is a property of both the Frame object and window object.
The top and parent properties are also synonyms that can be used in place of the frame name. top refers to the top-most window that contains frames or nested framesets, and parent refers to the window containing the current frameset. See the top and parent properties.
1. [frameReference.]frames[index]
2. [frameReference.]frames.length
3. [windowReference.]frames[index]
4. [windowReference.]frames.length
frameReference is a valid way of referring to a frame.
windowReference is a variable windowVar from a window definition (see the window object), or one of the synonyms top or parent.
To obtain the number of child frames in a window or frame, use the length property:
[windowReference.].frames.length
[frameReference.].frames.length
The Frame object has the following properties:
The frames array has the following properties:
Property | Description |
---|---|
length |
Reflects the number of child frames in the document
|
The Frame object has the following methods:
<HTML>
<HEAD>
<TITLE>Frames and Framesets: Window 1</TITLE>
</HEAD>
<FRAMESET ROWS="50%,50%" COLS="40%,60%"
onLoad="alert('Hello, World.')">
<FRAME SRC=framcon1.html NAME="frame1">
<FRAME SRC=framcon2.html NAME="frame2">
<FRAME SRC=framcon2.html NAME="frame3">
<FRAME SRC=framcon2.html NAME="frame4">
</FRAMESET>
</HTML>
framset2.html
, which defines the frames for
the second window, contains the following code:
<HTML>
<HEAD>
<TITLE>Frames and Framesets: Window 2</TITLE>
</HEAD>
<FRAMESET ROWS="50%,50%" COLS="40%,60%">
<FRAME SRC=framcon2.html NAME="frame1">
<FRAME SRC=framcon2.html NAME="frame2">
<FRAME SRC=framcon2.html NAME="frame3">
<FRAME SRC=framcon2.html NAME="frame4">
</FRAMESET>
</HTML>
<HTML>
<BODY>
<A NAME="frame1"><H1>Frame1</H1></A>
<P><A HREF="framcon3.htm" target=frame2>Click here</A>
to load a different file into frame 2.
<SCRIPT>
window2=open("framset2.htm","secondFrameset")
</SCRIPT>
<FORM>
<P><INPUT TYPE="button" VALUE="Change frame2 to teal"
onClick="parent.frame2.document.bgColor='teal'">
<P><INPUT TYPE="button" VALUE="Change frame3 to slateblue"
onClick="parent.frames[2].document.bgColor='slateblue'">
<P><INPUT TYPE="button" VALUE="Change frame4 to darkturquoise"
onClick="top.frames[3].document.bgColor='darkturquoise'">
<P><INPUT TYPE="button" VALUE="window2.frame2 to violet"
onClick="window2.frame2.document.bgColor='violet'">
<P><INPUT TYPE="button" VALUE="window2.frame3 to fuchsia"
onClick="window2.frames[2].document.bgColor='fuchsia'">
<P><INPUT TYPE="button" VALUE="window2.frame4 to deeppink"
onClick="window2.frames[3].document.bgColor='deeppink'">
</FORM>
</BODY>
</HTML>
framcon2.html
, which defines the content for
the remaining frames, contains the following code:
<HTML>
<BODY>
<P>This is a frame.
</BODY>
</HTML>
framcon3.html
, which is referenced in a
Link object in framcon1.html
, contains the following
code:
<HTML>
<BODY>
<P>This is a frame. What do you think?
</BODY>
</HTML>
document object, window object
Property. An array of objects corresponding to child frames (<FRAME> tag) in source order. See the Frame object for information.
Object. Specifies a string of JavaScript code to be compiled as a function.
functionObjectName = new Function ([arg1, arg2, ... argn], functionBody)
functionObjectName.propertyName
functionBody is a string specifying the JavaScript code to be compiled as the function body.
propertyName is one of the properties listed below.
In addition to defining functions as described here, you can also use the function statement, as described in "function".
var setBGColor = new Function("document.bgColor='antiquewhite'")
var colorChoice="antiquewhite"
if (colorChoice=="antiquewhite") {setBGColor()}
You can assign the function to an event handler in either of the following ways:
1. document.form1.colorButton.onclick=setBGColor
2. <INPUT NAME="colorButton" TYPE="button"
VALUE="Change background color"
onClick="setBGColor()">
Creating the variable setBGColor shown above is similar to declaring the following function:
function setBGColor() {
document.bgColor='antiquewhite'
}
Assigning a function to a variable is similar to declaring a function, but they have differences:
var setBGColor = new
Function("...")
, setBGColor is a variable for which the current
value is a reference to the function created with new Function()
.
function setBGColor() {...}
,
setBGColor is not a variable, it is the name of a function.
The following code specifies a Function object that takes two arguments.
var multFun = new Function("x", "y", "return x * y")
The following code shows several ways to call the function multFun:
var theAnswer = multFun(7,6)
document.write("15*2 = " + multFun(15,2))
<INPUT NAME="operand1" TYPE="text" VALUE="5" SIZE=5>
<INPUT NAME="operand2" TYPE="text" VALUE="6" SIZE=5>
<INPUT NAME="result" TYPE="text" VALUE="" SIZE=10>
<INPUT NAME="buttonM" TYPE="button" VALUE="Multiply"
onClick="document.form1.result.value=
multFun(document.form1.operand1.value,
document.form1.operand2.value)">
document.form1.button1.onclick=multFun(5,10)
window.onfocus = new Function("document.bgColor='antiquewhite'")
window.onfocus()
The Function object has the following properties:
Property | Description |
---|---|
arguments array |
Corresponds to elements of a function. |
caller |
Specifies which function called the current function
|
prototype |
Lets you add a properties to a Function object.
|
frames[0].onfocus = new Function("document.bgColor='antiquewhite'")
frames[0].onblur = new Function("document.bgColor='lightgrey'")
if (window.noFunc == null)
func1()
else func2()
Method. Returns the day of the month for the specified date.
dateObjectName.getDate()
dateObjectName is either the name of a Date object or a property of an existing object.
The value returned by getDate is an integer between one and 31.
Xmas95 = new Date("December 25, 1995 23:15:00")
day = Xmas95.getDate()
setDate method
Method. Returns the day of the week for the specified date.
dateObjectName.getDay()
dateObjectName is either the name of a Date object or a property of an existing object.
Xmas95 = new Date("December 25, 1995 23:15:00")
weekday = Xmas95.getDay()
Method. Returns the hour for the specified date.
dateObjectName.getHours()
dateObjectName is either the name of a Date object or a property of an existing object.
The value returned by getHours is an integer between zero and 23.
Xmas95 = new Date("December 25, 1995 23:15:00")
hours = Xmas95.getHours()
setHours method
Method. Returns the minutes in the specified date.
dateObjectName.getMinutes()
dateObjectName is either the name of a Date object or a property of an existing object.
The value returned by getMinutes is an integer between zero and 59.
Xmas95 = new Date("December 25, 1995 23:15:00")
minutes = Xmas95.getMinutes()
setMinutes method
Method. Returns the month in the specified date.
dateObjectName.getMonth()
dateObjectName is either the name of a Date object or a property of an existing object.
Xmas95 = new Date("December 25, 1995 23:15:00")
month = Xmas95.getDate()
setMonth method
Method. Returns the seconds in the current time.
dateObjectName.getSeconds()
dateObjectName is either the name of a Date object or a property of an existing object.
The value returned by getSeconds is an integer between zero and 59.
Xmas95 = new Date("December 25, 1995 23:15:30")
secs = Xmas95.getSeconds()
setSeconds method
Method. Returns the numeric value corresponding to the time for the specified date.
dateObjectName.getTime()
dateObjectName is either the name of a Date object or a property of an existing object.
The following example assigns the date value of theBigDay to sameAsBigDay:
theBigDay = new Date("July 1, 1999")
sameAsBigDay = new Date()
sameAsBigDay.setTime(theBigDay.getTime())
setTime method
Method. Returns the time-zone offset in minutes for the current locale.
dateObjectName.getTimezoneOffset()
dateObjectName is either the name of a Date object or a property of an existing object.
x = new Date()
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60
Method. Returns the year in the specified date.
dateObjectName.getYear()
dateObjectName is either the name of a Date object or a property of an existing object.
The getYear method returns either a two-digit or four-digit year:
Xmas95 = new Date("December 25, 1995 23:15:00")
year = Xmas95.getYear()
newYears2026 = new Date("2026, January, 1")
theYear = newYears2026.getYear()
setYear method
Method. Loads a URL from the history list.
history.go(delta | "location")
The location argument is a string. Use location to load the nearest history entry whose URL contains location as a substring. The location to URL matching is case-insensitive. Each section of a URL contains different information. See the location object for a description of the URL components.
The go method creates a new entry in the history list. To load a URL without creating an entry in the history list, use replace.
<P><INPUT TYPE="button" VALUE="Go"
onClick="history.go('home.netscape.com')">
The following button navigates to the URL that is three entries backward in the history list:
<P><INPUT TYPE="button" VALUE="Go"
onClick="history.go(-3)">
back, forward, reload, replace methods
file: /Techref/language/java/script/ref_f-g.htm, 93KB, , updated: 2009/2/2 13:27, local time: 2024/11/8 18:51,
3.144.228.11:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.org/techref/language/java/script/ref_f-g.htm"> fgColor </A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to massmind.org! |
.