document.fgcolor
implemented in
navigator 2.0
tainted?
no
description
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.
if you express the color as a hexadecimal rgb triplet, you must use the format rrggbb. for example, the hexadecimal rgb values for salmon are red=fa, green=80, and blue=72, so the rgb triplet for salmon is "fa8072."
document.fgcolor="aqua"the following example sets the color of the foreground text to aqua using a hexadecimal triplet:
document.fgcolor="00ffff"
1. navigator.plugins[index].filename
2. navigator.plugins[pluginname].filename
implemented in
navigator 3.0
tainted?
no
description
the filename property is the plug-in program's file name and is supplied by the plug-in itself. this name may vary from platform to platform.
examples
see the examples for the plugin object.
see also
description, length, name properties
<input
type="file"
name="fileuploadname"
[onblur="handlertext"]
[onchange="handlertext"]
[onfocus="handlertext"]
>
fileuploadname.propertyname
fileuploadname.methodname
propertyname is one of the properties listed below.
methodname is one of the properties listed below.
implemented in
navigator 3.0
description
a fileupload object on a form looks as follows:
properties
the fileupload object has the following properties:
methods
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>
stringname.fixed()
implemented in
navigator 2.0
description
use the fixed method with the write or writeln methods to format and display a string in a document.
examples
the following example uses the fixed method to change the formatting of a string:var worldstring="hello, world"
the previous example produces the same output as the following html:
document.write(worldstring.fixed())<tt>hello, world</tt>
math.floor(number)
implemented in
navigator 2.0
examples
the following function returns the floor value of the variable x:function getfloor(x) {
if you pass getfloor the value 45.95, it returns 45; if you pass it the value -45.95, it returns -46.
return math.floor(x)
}
see also
ceil method
1. fileuploadname.focus()
2. passwordname.focus()
3. selectname.focus()
4. textname.focus()
5. textareaname.focus()
6. framereference.focus()
7. windowreference.focus()
passwordname is either the value of the name attribute of a password object or an element in the elements array.
selectname is either the value of the name attribute of a select 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.
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.
method of
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) {this example assumes that the password object is defined as
if (badpassword) {
alert("please enter your password again.")
userpass.focus()
userpass.select()
}
}
<input type="password" name="userpass">
stringname.fontcolor(color)
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".
implemented in
navigator 2.0
description
use the fontcolor method with the write or writeln methods to format and display a string in a document.
examples
the following example uses the fontcolor method to change the color of a string:var worldstring="hello, world"
the previous example produces the same output as the following html:
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")<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)
size is an integer between one and seven, a string representing a signed integer between one and seven, or a property of an existing object.
implemented in
navigator 2.0
description
use the fontsize method with the write or writeln methods to format and display a string in a document.
examples
the following example uses string methods to change the size of a string:var worldstring="hello, world"
the previous example produces the same output as the following html:
document.write(worldstring.small())
document.write("<p>" + worldstring.big())
document.write("<p>" + worldstring.fontsize(7))<small>hello, world</small>
<p><big>hello, world</big>
<p><fontsize=7>hello, world</fontsize>
see also
big, small methods
<form
name="formname"
target="windowname"
action="serverurl"
method=get | post
enctype="encodingtype"
[onreset="handlertext"]
[onsubmit="handlertext"]>
</form>
target="windowname" specifies the window that form responses go to. when you submit a form with a target attribute, server responses are displayed in the specified window instead of the window that contains the form. windowname can be an existing window; it can be a frame name specified in a <frameset> tag; or it can be one of the literal frame names _top, _parent, _self, or _blank; it cannot be a javascript expression (for example, it cannot be parent.framename or windowname.framename). you can access this value using the target property.
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.
method=get | post specifies how information is sent to the server specified by action. get (the default) appends the input information to the url, which on most receiving systems becomes the value of the environment variable query_string. post sends the input information in a data body, which is available on stdin with the data length set in the environment variable content_length. if the method attribute has the value "post," then the enctype attribute typically has the value "application/x-www-form-urlencoded." you can access this value using the method property.
enctype="encodingtype" specifies the mime encoding of the data sent: "application/x-www-form-urlencoded" (the default) or "multipart/form-data." use "multipart/form-data" if the form contains a file upload element (input type="file"). if the method attribute has the value "post," then the enctype attribute typically has the value "application/x-www-form-urlencoded." you can access this value using the encoding property.
1. formname.propertyname
2. formname.methodname(parameters)
3. forms[index].propertyname
4. forms[index].methodname(parameters)
index is an integer representing a form object or the name of a form object as specified by the name attribute.
propertyname is one of the properties listed below.
methodname is one of the methods listed below.
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.
the forms array
you can reference the forms in your code by using the forms array (you can also use the form name). this array contains an entry for each form object (<form> tag) in a document in source order. for example, if a document contains three forms, these forms are reflected as document.forms[0]
, document.forms[1]
, and document.forms[2]
.1. document.forms[index]
index is an integer representing a form in a document or the name of a form object as specified by the name attribute.
2. document.forms.lengthdocument.forms.length
.document.forms[1].quantity
. you would refer to the value property of this text object as document.forms[1].quantity.value
.document.forms[0]="music"
has no effect.object nameattribute>
, where nameattribute is the name attribute of the form.
properties
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
| |
---|
methods
the form object has the following methods:
|
|
<html>example 2: forms array. the onload event handler in the following example displays the name of the first form in an alert dialog box.
<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!example 3: onsubmit event handler. the following example shows an onsubmit event handler that determines whether to submit a form. the form contains one text object where the user enters three characters. the onsubmit event handler calls a function, checkdata, that returns true if the number of characters is three; otherwise, it returns false. notice that the form's onsubmit event handler, not the submit button's onclick event handler, calls the checkdata function. also, the onsubmit event handler contains a return statement that returns the value obtained with the function call.
<html>example 4: submit method. the following example is similar to the previous one, except it submits the form using the submit method instead of a submit object. the form's onsubmit event handler does not prevent the form from being submitted. the form uses a button's onclick event handler to call the checkdata function. if the value is valid, the checkdata function submits the form by calling the form's submit method.
<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>
this.form
objectreference.form
implemented in
navigator 2.0
tainted?
no
description
each form element has a form property that is a reference to the element's parent form. this property is especially useful in event handlers, where you might need to refer to another element on the current form.
examples
example 1. in the following example, the form myform contains a text object and a button. when the user clicks the button, the value of the text object is set to the form's name. the button's onclick event handler uses this.form
to refer to the parent form, myform.<form name="myform">
example 2. the following example shows a form with several elements. when the user clicks button2, the function showelements displays an alert dialog box containing the names of each element on the form 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) {
the alert dialog box displays the following text:
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>javascript alert:
example 3. the following example uses an object reference, rather than the this keyword, to refer to a form. the code returns a reference to myform, which is a form containing mytextobject.
form elements of form myform:
text1
button1
button2document.myform.mytextobject.form
see also
form object
history.forward()
implemented in
navigator 2.0
description
this method performs the same action as a user choosing the forward button in the navigator. the forward method is the same as history.go(1)
.
examples
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()">
see also
back, go methods
<frameset
rows="rowheightlist"
cols="columnwidthlist"
[onblur="handlertext"]
[onfocus="handlertext"]
[onload="handlertext"]
[onunload="handlertext"]>
<frame src="url" name="framename">
[ ... <frame src="url" name="framename">]
</frameset>
cols="columnwidthlist" is a comma-separated list of values specifying the column-width of the frame. an optional suffix defines the units. default units are pixels.
<frame> defines a frame.
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.name="framename" specifies a name to be used as a target of hyperlink jumps. you can access this value using the name property, and you can use this name when indexing the frames array.
1. [windowreference.]framename.propertynameto define an onblur or onfocus event handler for a frame (for frames, you cannot specify these event handlers in html):
2. [windowreference.]frames[index].propertyname
3. window.propertyname
4. self.propertyname
5. parent.propertyname
1. framereference.onblur=errorhandler
2. framereference.onfocus=errorhandler
framename is the value of the name attribute in the <frame> tag of a frame object.
property of
the frame object is a property of the window object.
the frames array is a property of both the frame object and window object.
if a <frame> tag contains src and name attributes, you can refer to that frame from a sibling frame by using
parent.framename
or parent.frames[index]
. for example, if the fourth frame in a set has name="homeframe," sibling frames can refer to that frame using parent.homeframe
or parent.frames[3]
.the self and window properties are synonyms for the current frame, and you can optionally use them to refer to the current frame. you can use these properties to make your code more readable. see the properties listed below for examples.
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.
to create an onblur or onfocus event handler for a frame, you must set the onblur or onfocus property and specify it in all lowercase (you cannot specify it in html).
the frames array
you can reference the frame objects in your code by using the frames array. this array contains an entry for each child frame (<frame> tag) in a window containing a <frameset> tag in source order. for example, if a window contains three child frames, these frames are reflected as parent.frames[0]
, parent.frames[1]
, and parent.frames[2]
.1. [framereference.]frames[index]
framereference is a valid way of referring to a frame.
2. [framereference.]frames.length
3. [windowreference.]frames[index]
4. [windowreference.]frames.length
index is an integer representing a frame in a parent window or the name of a frame object as specified by the name attribute.
[windowreference.].frames.length
elements in the frames array are read-only. for example, the statement
[framereference.].frames.lengthwindowreference.frames[0]="frame1"
has no effect.object nameattribute>
, where nameattribute is the name attribute of the frame.
properties
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
| |
---|
methods
the frame object has the following methods:
|
|
framset1.html
, which defines the frames for the first window, contains the following code:
<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>
framcon1.html
, which defines the content for the first frame in the first window, contains the following code:
<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>
functionobjectname = new function ([arg1, arg2, ... argn], functionbody)to use a function object:
functionobjectname.propertyname
window.onerror
. when using function properties, functionobjectname is either the name of an existing function object or a property of an existing object.arg1, arg2, ... argn are arguments to be used by the function as formal argument names. each must be a string that corresponds to a valid javascript identifier; for example "x" or "theform".
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".
specifying a variable value with a function object
the following code assigns a function to the variable setbgcolor. this function sets the current document's background color.var setbgcolor = new function("document.bgcolor='antiquewhite'")
to call the function object, you can specify the variable name as if it were a function. the following code executes the function specified by the setbgcolor variable:var colorchoice="antiquewhite"
you can assign the function to an event handler in either of the following ways:
if (colorchoice=="antiquewhite") {setbgcolor()}1. document.form1.colorbutton.onclick=setbgcolor
creating the variable setbgcolor shown above is similar to declaring the following function:
2. <input name="colorbutton" type="button"
value="change background color"
onclick="setbgcolor()">function setbgcolor() {
assigning a function to a variable is similar to declaring a function, but they have differences:
document.bgcolor='antiquewhite'
}
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.
var multfun = new function("x", "y", "return x * y")the string arguments "x" and "y" are formal argument names that are used in the function body, "return x * y".
the following code shows several ways to call the function multfun:
var theanswer = multfun(7,6)you cannot call the function multfun in an object's event handler property, because event handler properties cannot take arguments. for example, you cannot call the function multfun by setting a button's onclick property as follows:
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'")once you have a reference to a function object, you can use it like a function and it will convert from an object to a function:
window.onfocus()event handlers do not take arguments, so you cannot declare any arguments in the function() constructor for an event handler.
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'")example 2. you can determine whether a function exists by comparing the function name to null. in the following example, func1 is called if the function nofunc does not exist; otherwise func2 is called. notice that the window name is needed when referring to the function name nofunc.
frames[0].onblur = new function("document.bgcolor='lightgrey'")
if (window.nofunc == null)
func1()
else func2()
dateobjectname.getdate()
implemented in
navigator 2.0
description
the value returned by getdate is an integer between one and 31.
examples
the second statement below assigns the value 25 to the variable day, based on the value of the date object xmas95.xmas95 = new date("december 25, 1995 23:15:00")
day = xmas95.getdate()
see also
setdate method
dateobjectname.getday()
implemented in
navigator 2.0
description
the value returned by getday is an integer corresponding to the day of the week: zero for sunday, one for monday, two for tuesday, and so on.
examples
the second statement below assigns the value 1 to weekday, based on the value of the date object xmas95. this is because december 25, 1995, is a monday.xmas95 = new date("december 25, 1995 23:15:00")
weekday = xmas95.getday()
dateobjectname.gethours()
implemented in
navigator 2.0
description
the value returned by gethours is an integer between zero and 23.
examples
the second statement below assigns the value 23 to the variable hours, based on the value of the date object xmas95.xmas95 = new date("december 25, 1995 23:15:00")
hours = xmas95.gethours()
see also
sethours method
dateobjectname.getminutes()
implemented in
navigator 2.0
description
the value returned by getminutes is an integer between zero and 59.
examples
the second statement below assigns the value 15 to the variable minutes, based on the value of the date object xmas95.xmas95 = new date("december 25, 1995 23:15:00")
minutes = xmas95.getminutes()
see also
setminutes method
dateobjectname.getmonth()
implemented in
navigator 2.0
description
the value returned by getmonth is an integer between zero and 11. zero corresponds to january, one to february, and so on.
examples
the second statement below assigns the value 11 to the variable month, based on the value of the date object xmas95.xmas95 = new date("december 25, 1995 23:15:00")
month = xmas95.getdate()
see also
setmonth method
dateobjectname.getseconds()
implemented in
navigator 2.0
description
the value returned by getseconds is an integer between zero and 59.
examples
the second statement below assigns the value 30 to the variable secs, based on the value of the date object xmas95.xmas95 = new date("december 25, 1995 23:15:30")
secs = xmas95.getseconds()
see also
setseconds method
dateobjectname.gettime()
implemented in
navigator 2.0
description
the value returned by the gettime method is the number of milliseconds since 1 january 1970 00:00:00. you can use this method to help assign a date and time to another date object.
examples
the following example assigns the date value of thebigday to sameasbigday:thebigday = new date("july 1, 1999")
sameasbigday = new date()
sameasbigday.settime(thebigday.gettime())
see also
settime method
dateobjectname.gettimezoneoffset()
implemented in
navigator 2.0
description
the time-zone offset is the difference between local time and gmt. daylight savings time prevents this value from being a constant.
examples
x = new date()
currenttimezoneoffsetinhours = x.gettimezoneoffset()/60
dateobjectname.getyear()
implemented in
navigator 2.0
description
the getyear method returns either a two-digit or four-digit year:
xmas95 = new date("december 25, 1995 23:15:00")example 2. the second statement below assigns the value 2026 to the variable theyear, based on the value of the date object newyears2026.
year = xmas95.getyear()
newyears2026 = new date("2026, january, 1")
theyear = newyears2026.getyear()
history.go(delta | "location")
location is a string or a property of an existing object, representing all or part of a url in the history list.
implemented in
navigator 2.0
description
the go method navigates to the location in the history list determined by the argument that you specify. you can interactively display the history list by choosing history from the window menu. up to 10 items in the history list are also displayed on the go menu.
examples
the following button navigates to the nearest history entry that contains the string "home.netscape.com":<p><input type="button" value="go"
the following button navigates to the url that is three entries backward in the history list:
onclick="history.go('home.netscape.com')"><p><input type="button" value="go"
onclick="history.go(-3)">
see also
back, forward, reload, replace methods