windowreference.scroll(x-coordinate,y-coordinate)
x-coordinate is an integer representing the x-coordinate in pixels.
method of
window object
implemented in
navigator 3.0
description
javascript does not reflect document dimensions in pixels, so when using the scroll method, you must hardcode the x and y coordinates. a document's upper left coordinates are 0,0.
examples
example 1: scroll the current window. the following example scrolls the current window to the coordinates 50,100.window.scroll(50,100)
example 2: scroll a different window. the following code, which exists in one frame, scrolls a second frame. two text objects let the user specify the x and y coordinates. when the user clicks the go button, the document in frame2 scrolls to the specified coordinates.<script>
function scrollit(form) {
var x = parseint(form.x.value)
var y = parseint(form.y.value)
parent.frame2.scroll(x, y)
}
</script>
<body>
<form name="myform">
<p><b>specify the coordinates to scroll to:</b>
<br>horizontal:
<input type="text" name=x value="0" size=4>
<br>vertical:
<input type="text" name=y value="0" size=4>
<br><input type="button" value="go"
onclick="scrollit(document.myform)">
</form>
1. links[index].search
2. location.search
3. areaname.search
areaname is the value of the name attribute of an area object.
the search property contains variable and value pairs; each pair is separated by an ampersand. for example, two pairs in a search string could look like the following:
?x=7&y=5you can set the search property at any time, although it is safer to set the href property to change a location. if the search that you specify cannot be found in the current location, you will get an error.
in event handlers, you must specify
window.location.search
instead of simply using location.search
. due to the scoping of static objects in javascript, a call to location
without specifying an object name is equivalent to document.location
, which is a synonym for document.url
.see section 3.3 of rfc 1738 for complete information about the search.
examples
in the following example, the window.open
statement creates a window called newwindow and loads the specified url into it. the document.write
statements display all the properties of newwindow.location
in a window called msgwindow.newwindow=window.open
the previous example displays the following output:
("http://guide-p.infoseek.com/ww/ns/titles?qt=rfc+1738+&col=ww")
msgwindow.document.write("newwindow.location.href = " +
newwindow.location.href + "<p>")
msgwindow.document.write("newwindow.location.protocol = " +
newwindow.location.protocol + "<p>")
msgwindow.document.write("newwindow.location.host = " +
newwindow.location.host + "<p>")
msgwindow.document.write("newwindow.location.hostname = " +
newwindow.location.hostname + "<p>")
msgwindow.document.write("newwindow.location.port = " +
newwindow.location.port + "<p>")
msgwindow.document.write("newwindow.location.pathname = " +
newwindow.location.pathname + "<p>")
msgwindow.document.write("newwindow.location.hash = " +
newwindow.location.hash + "<p>")
msgwindow.document.write("newwindow.location.search = " +
newwindow.location.search + "<p>")
msgwindow.document.close()newwindow.location.href =
http://guide-p.infoseek.com/ww/ns/titles?qt=rfc+1738+&col=ww
newwindow.location.protocol = http:
newwindow.location.host = guide-p.infoseek.com
newwindow.location.hostname = guide-p.infoseek.com
newwindow.location.port =
newwindow.location.pathname = /ww/ns/titles
newwindow.location.hash =
newwindow.location.search = ?qt=rfc+1738+&col=ww
see also
hash, host, hostname, href, pathname, port, protocol properties
1. passwordname.select()
2. textname.select()
3. textareaname.select()
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.
implemented in
navigator 2.0
description
use the select method to highlight the input area of a form element. you can use the select method with the focus method to highlight a field and position the cursor for a user response.
examples
in the following example, the checkpassword function confirms that a user has entered a valid password. if the password is not valid, the select method highlights the password field and the focus method returns focus to it so the user can re-enter the password.function checkpassword(userpass) {
this example assumes that the password is defined as
if (badpassword) {
alert("please enter your password again.")
userpass.focus()
userpass.select()
}
}<input type="password" name="userpass">
see also
blur, focus methods
<select
name="selectname"
[size="integer"]
[multiple]
[onblur="handlertext"]
[onchange="handlertext"]
[onfocus="handlertext"]>
<option value="optionvalue" [selected]> texttodisplay
[ ... <option> texttodisplay]
</select>
size="integer" specifies the number of options visible when the form is displayed.
multiple specifies that multiple items can be selected. if omitted, only one item can be selected from the list.
option specifies a selection element in the list. you can access the options using the options array.
value="optionvalue" specifies a value that is returned to the server when the option is selected and the form is submitted. you can access this value using the value property.
selected specifies that the option is selected by default. you can access this value using the defaultselected property.
texttodisplay specifies the text to display in the list. you can access this value using the text property.
optionname = new option([text, value, defaultselected, selected])to add the new option to an existing select object:
selectname.options[index1]=optionnameto delete an option from a select object:
selectname.options[index1] = nullto use a select object's properties and methods:
1. selectname.propertynameto use an option's properties:
2. selectname.methodname(parameters)
3. formname.elements[index].propertyname
4. formname.elements[index].methodname(parameters)
1. selectname.options[index1].propertyname
2. formname.elements[index2].options[index1].propertyname
3. optionname.propertyname
text specifies the text to display in the select list. you can access this value using the text property.
value specifies a value that is returned to the server when the option is selected and the form is submitted. you can access this value using the value property.
defaultselected specifies whether the option is initially selected (true or false). you can access this value using the defaultselected property.
selected specifies the current selection state of the option (true or false). you can access this value using the selected property.
selectname is the value of the name attribute of a select object.
formname is either the value of the name attribute of a form object or an element in the forms array.
index is an integer representing a select object on a form or the name of a select object as specified by the name attribute.
index1 is an integer representing an option in a select object.
index2 is an integer representing a select object on a form.
propertyname is one of the properties listed below.
methodname is one of the methods listed below.
a select object is a form element and must be defined within a <form> tag.
musicstyle.options[0]
, musicstyle.options[1]
, and musicstyle.options[2]
.to use the options array:
1. selectname.optionsselectname is either the value of the name attribute of a select object or an element in the elements array.
2. selectname.options[index]
3. selectname.options.length
index is an integer representing an option in a select object.
to obtain the number of options in a select object, use the length property of either the options array or the select object:
1. selectname.lengththe select object has properties that you can access only through the options array. these properties are listed below.
2. selectname.options.length
each element in the options array represents a select option; the value returned by selectname.options represents the full html statement for the selectname object.
elements in the options array are read-only. for example, the statement
selectname.options[0]="guitar"
has no effect.for select objects that can have multiple selections (the <select> tag has the multiple attribute), you have to loop and test each option individually:
for (var i = 0; i < select.options.length; i++) {
if (select.options[i].selected)
// statements to perform if option is selected
...
}
document.myform.musictypes.selectedindex = i
document.myform.musictypes.options[i].selected = true
<select name="userchoice">you can set the text of the ith item in the selection based on text entered in a text field named whatsnew as follows:
<option>choice 1
<option>choice 2
<option>choice 3
</select>
myform.userchoice.options[i].text = myform.whatsnew.valueyou do not need to reload or refresh after changing an option's text.
for example, in the following form, the user can enter some text in the first text field and then enter a number between 0 and 2 (inclusive) in the second text field. when the user clicks the button, the text will be substituted for the indicated option number and that option is selected.
the code for this example looks as follows:
<script>
function updatelist(theform, i) {
theform.userchoice.options[i].text = theform.whatsnew.value
theform.userchoice.options[i].selected = true
}
</script>
<form>
<select name="userchoice">
<option>choice 1
<option>choice 2
<option>choice 3
</select>
<br>
new text for the option: <input type="text" name="whatsnew">
<br>
option to change (0, 1, or 2): <input type="text" name="idx">
<br>
<input type="button" value="change selection"
onclick="updatelist(this.form, this.form.idx.value)">
</form>
after you create the options and add them to the select object, you must refresh the document by using
history.go(0)
. this statement must be last. when the document reloads, variables are lost if not saved in cookies or form element values.
after you delete an option, you must refresh the document by using
history.go(0)
. this statement must be last. when the document reloads, variables are lost if not saved in cookies or form element values.
the options array has the following properties:
property |
description
length
|
reflects the number of options in a select object
|
selectedindex
|
reflects the index of the selected option
| |
---|
each element of the options array has the following properties:
objects created with the option() constructor have the following properties:
methods
the select object has the following methods:
|
|
choose the music type for your free cd:example 2. the following example displays two selection lists that let the user choose a month and day. these selection lists are initialized to the current date. the user can change the month and day by using the selection lists or by choosing preset dates from radio buttons. text fields on the form display the values of the select object's properties and indicate the date chosen and whether it is cinco de mayo.
<select name="music_type_single">
<option selected> r&b
<option> jazz
<option> blues
<option> new age
</select>
<p>choose the music types for your free cds:
<br><select name="music_type_multi" multiple>
<option selected> r&b
<option> jazz
<option> blues
<option> new age
</select>
<html>example 3. add an option using the option() constructor. the following example creates two select objects, one without the multiple attribute and one with. no options are initially defined for either object. when the user clicks a button associated with the select object, the populate function creates four options for the select object and selects the first option.
<head>
<title>select object example</title>
</head>
<body>
<script>
var today = new date()
//---------------
function updatepropertydisplay(monthobj,dayobj) {
// get date strings
var monthinteger, dayinteger, monthstring, daystring
monthinteger=monthobj.selectedindex
dayinteger=dayobj.selectedindex
monthstring=monthobj.options[monthinteger].text
daystring=dayobj.options[dayinteger].text
// display property values
document.selectform.textfulldate.value=monthstring + " " + daystring
document.selectform.textmonthlength.value=monthobj.length
document.selectform.textdaylength.value=dayobj.length
document.selectform.textmonthname.value=monthobj.name
document.selectform.textdayname.value=dayobj.name
document.selectform.textmonthindex.value=monthobj.selectedindex
document.selectform.textdayindex.value=dayobj.selectedindex
// is it cinco de mayo?
if (monthobj.options[4].selected && dayobj.options[4].selected)
document.selectform.textcinco.value="yes!"
else
document.selectform.textcinco.value="no"
}
</script>
<!--------------->
<form name="selectform">
<p><b>choose a month and day:</b>
month: <select name="monthselection"
onchange="updatepropertydisplay(this,document.selectform.dayselection)">
<option> january <option> february <option> march
<option> april <option> may <option> june
<option> july <option> august <option> september
<option> october <option> november <option> december
</select>
day: <select name="dayselection"
onchange="updatepropertydisplay(document.selectform.monthselection,this)">
<option> 1 <option> 2 <option> 3 <option> 4 <option> 5
<option> 6 <option> 7 <option> 8 <option> 9 <option> 10
<option> 11 <option> 12 <option> 13 <option> 14 <option> 15
<option> 16 <option> 17 <option> 18 <option> 19 <option> 20
<option> 21 <option> 22 <option> 23 <option> 24 <option> 25
<option> 26 <option> 27 <option> 28 <option> 29 <option> 30
<option> 31
</select>
<p><b>set the date to: </b>
<input type="radio" name="datechoice"
onclick="
monthselection.selectedindex=0;
dayselection.selectedindex=0;
updatepropertydisplay
document.selectform.monthselection,document.selectform.dayselection)">
new year's day
<input type="radio" name="datechoice"
onclick="
monthselection.selectedindex=4;
dayselection.selectedindex=4;
updatepropertydisplay
(document.selectform.monthselection,document.selectform.dayselection)">
cinco de mayo
<input type="radio" name="datechoice"
onclick="
monthselection.selectedindex=5;
dayselection.selectedindex=20;
updatepropertydisplay
(document.selectform.monthselection,document.selectform.dayselection)">
summer solstice
<p><b>property values:</b>
<br>date chosen: <input type="text" name="textfulldate" value="" size=20">
<br>monthselection.length<input type="text" name="textmonthlength" value="" size=20">
<br>dayselection.length<input type="text" name="textdaylength" value="" size=20">
<br>monthselection.name<input type="text" name="textmonthname" value="" size=20">
<br>dayselection.name<input type="text" name="textdayname" value="" size=20">
<br>monthselection.selectedindex
<input type="text" name="textmonthindex" value="" size=20">
<br>dayselection.selectedindex<input type="text" name="textdayindex" value="" size=20">
<br>is it cinco de mayo? <input type="text" name="textcinco" value="" size=20">
<script>
document.selectform.monthselection.selectedindex=today.getmonth()
document.selectform.dayselection.selectedindex=today.getdate()-1
updatepropertydisplay(document.selectform.monthselection,document.selectform.dayselection)
</script>
</form>
</body>
</html>
<script>example 4. delete an option. the following function removes an option from a select object.
function populate(inform) {
colorarray = new array("red", "blue", "yellow", "green")
var option0 = new option("red", "color_red")
var option1 = new option("blue", "color_blue")
var option2 = new option("yellow", "color_yellow")
var option3 = new option("green", "color_green")
for (var i=0; i < 4; i++) {
eval("inform.selecttest.options[i]=option" + i)
if (i==0) {
inform.selecttest.options[i].selected=true
}
}
history.go(0)
}
</script>
<h3>select option() constructor</h3>
<form>
<select name="selecttest"></select><p>
<input type="button" value="populate select list" onclick="populate(this.form)">
<p>
</form>
<hr>
<h3>select-multiple option() constructor</h3>
<form>
<select name="selecttest" multiple></select><p>
<input type="button" value="populate select list" onclick="populate(this.form)">
</form>
function deleteanitem(thelist,itemno) {see also the examples for the defaultselected property.
thelist.options[itemno]=null
history.go(0)
}
1. selectname.options[index].selected
2. optionname.selected
index is an integer representing an option in a select object.
optionname is the name of a select object option created using the option() constructor.
you can set the selected property at any time. the display of the select object updates immediately when you set the selected property.
in general, the selected property is more useful than the selectedindex property for select objects that are created with the multiple attribute. with the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options.
see also
defaultselected, index, selectedindex properties
1. selectname.selectedindex
2. selectname.options.selectedindex
implemented in
navigator 2.0
tainted?
yes
description
options in a select object are indexed in the order in which they are defined, starting with an index of zero. you can set the selectedindex property at any time. the display of the select object updates immediately when you set the selectedindex property. both forms of the syntax specify the same value. if no option is selected, selectedindex has a value of -1.
examples
in the following example, the getselectedindex function returns the selected index in the musictype select object:function getselectedindex() {
the previous example assumes that the select object is similar to the following:
return document.musicform.musictype.selectedindex
}<select name="musictype">
<option selected> r&b
<option> jazz
<option> blues
<option> new age
</select>
see also
defaultselected, index, selected properties
1. self.propertyname
2. self.methodname
propertyname is the length or name property when self refers to a frame object.
methodname is any method associated with the window object.
implemented in
navigator 2.0
tainted?
no
description
the self property refers to the current window or frame. <object nameattribute>
where nameattribute is the name attribute if self refers to a frame, or an internal reference if self refers to a window.
examples
in the following example, self.status
is used to set the status property of the current window. this usage disambiguates the status property of the current window from a form or form element called "status" within the current window.<a href=""
onclick="this.href=pickrandomurl()"
onmouseover="self.status='pick a random url' ; return true">
go!</a>
see also
window property
dateobjectname.setdate(dayvalue)
dayvalue is an integer from one to 31 or a property of an existing object, representing the day of the month.
implemented in
navigator 2.0
examples
the second statement below changes the day for thebigday to july 24 from its original value.thebigday = new date("july 27, 1962 23:30:00")
thebigday.setdate(24)
see also
getdate method
dateobjectname.sethours(hoursvalue)
hoursvalue is an integer between zero and 23 or a property of an existing object, representing the hour.
implemented in
navigator 2.0
examples
thebigday.sethours(7)
see also
gethours method
dateobjectname.setminutes(minutesvalue)
minutesvalue is an integer between zero and 59 or a property of an existing object, representing the minutes.
implemented in
navigator 2.0
examples
thebigday.setminutes(45)
see also
getminutes method
dateobjectname.setmonth(monthvalue)
monthvalue is an integer between zero and 11 (representing the months january through december) or a property of an existing object.
implemented in
navigator 2.0
examples
thebigday.setmonth(6)
see also
getmonth method
dateobjectname.setseconds(secondsvalue)
secondsvalue is an integer between zero and 59 or a property of an existing object.
implemented in
navigator 2.0
examples
thebigday.setseconds(30)
see also
getseconds method
dateobjectname.settime(timevalue)
timevalue is an integer or a property of an existing object, representing the number of milliseconds since the epoch (1 january 1970 00:00:00).
implemented in
navigator 2.0
description
use the settime method to help assign a date and time to another date object.
examples
thebigday = new date("july 1, 1999")
sameasbigday = new date()
sameasbigday.settime(thebigday.gettime())
see also
gettime method
timeoutid=settimeout(expression, msec)
expression is a string expression or a property of an existing object.
msec is a numeric value, numeric string, or a property of an existing object in millisecond units.
implemented in
navigator 2.0
description
the settimeout method evaluates an expression after a specified amount of time. it does not evaluate the expression repeatedly. for example, if a settimeout method specifies five seconds, the expression is evaluated after five seconds, not every five seconds.
examples
example 1. the following example displays an alert message five seconds (5,000 milliseconds) after the user clicks a button. if the user clicks the second button before the alert message is displayed, the timeout is canceled and the alert does not display.<script language="javascript">
example 2. the following example displays the current time in a text object. the showtime function, which is called recursively, uses the settimeout method to update the time every second.
function displayalert() {
alert("5 seconds have elapsed since the button was clicked.")
}
</script>
<body>
<form>
click the button on the left for a reminder in 5 seconds;
click the button on the right to cancel the reminder before
it is displayed.
<p>
<input type="button" value="5-second reminder"
name="remind_button"
onclick="timerid=settimeout('displayalert()',5000)">
<input type="button" value="clear the 5-second reminder"
name="remind_disable_button"
onclick="cleartimeout(timerid)">
</form>
</body><head>
<script language="javascript">
<!--
var timerid = null
var timerrunning = false
function stopclock(){
if(timerrunning)
cleartimeout(timerid)
timerrunning = false
}
function startclock(){
// make sure the clock is stopped
stopclock()
showtime()
}
function showtime(){
var now = new date()
var hours = now.gethours()
var minutes = now.getminutes()
var seconds = now.getseconds()
var timevalue = "" + ((hours > 12) ? hours - 12 : hours)
timevalue += ((minutes < 10) ? ":0" : ":") + minutes
timevalue += ((seconds < 10) ? ":0" : ":") + seconds
timevalue += (hours >= 12) ? " p.m." : " a.m."
document.clock.face.value = timevalue
timerid = settimeout("showtime()",1000)
timerrunning = true
}
//-->
</script>
</head>
<body onload="startclock()">
<form name="clock" onsubmit="0">
<input type="text" name="face" size=12 value ="">
</form>
</body>
see also
cleartimeout method
dateobjectname.setyear(yearvalue)
yearvalue is an integer greater than 1900 or a property of an existing object.
implemented in
navigator 2.0
examples
thebigday.setyear(96)
see also
getyear method
math.sin(number)
implemented in
navigator 2.0
description
the sin method returns a numeric value between -1 and one, which represents the sine of the argument.
examples
the following function returns the sine of the variable x:function getsine(x) {
if you pass getsine the value
return math.sin(x)
}math.pi/2
, it returns 1.
see also
acos, asin, atan, atan2, cos, tan methods
stringname.small()
implemented in
navigator 2.0
description
use the small 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, fontsize methods
arrayname.sort(comparefunction)
comparefunction specifies a function that defines the sort order. if omitted, the array is sorted lexicographically (in dictionary order) according to the string conversion of each element.
implemented in
navigator 3.0
description
if comparefunction is not supplied, elements are sorted by converting them to strings and comparing strings in lexicographic ("dictionary" or "telephone book," not numerical) order. for example, "80" comes before "9" in lexicographic order, but if you are comparing numbers 9 needs to come before 80.
function compare(a, b) {to compare numbers instead of strings, the compare function can simply subtract b from a:
if (a is less than b by some ordering criterion)
return -1
if (a is greater than b by the ordering criterion)
return 1
// a must be equal to b
return 0
}
function comparenumbers(a, b) {javascript uses a stable sort: the index partial order of a and b does not change if a and b are equal. if a's index was less than b's before sorting, it will be after sorting, no matter how a and b move due to sorting.
return a - b
}
note
on some platforms, the sort method does not work. please see the release notes (after starting netscape, choose release notes from the help menu).
<script>this example produces the following output. as the output shows, when a compare function is used, numbers sort correctly whether they are numbers or numeric strings.
stringarray = new array("blue","humpback","beluga")
numericstringarray = new array("80","9","700")
numberarray = new array(40,1,5,200)
mixednumericarray = new array("80","9","700",40,1,5,200)
function comparenumbers(a, b) {
return a - b
}
document.write("<b>stringarray:</b> " + stringarray.join() +"<br>")
document.write("<b>sorted:</b> " + stringarray.sort() +"<p>")
document.write("<b>numberarray:</b> " + numberarray.join() +"<br>")
document.write("<b>sorted without a compare function:</b> " + numberarray.sort() +"<br>")
document.write("<b>sorted with comparenumbers:</b> " + numberarray.sort(comparenumbers) +"<p>")
document.write("<b>numericstringarray:</b> " + numericstringarray.join() +"<br>")
document.write("<b>sorted without a compare function:</b> " + numericstringarray.sort() +"<br>")
document.write("<b>sorted with comparenumbers:</b> " + numericstringarray.sort(comparenumbers) +"<p>")
document.write("<b>mixednumericarray:</b> " + mixednumericarray.join() +"<br>")
document.write("<b>sorted without a compare function:</b> " + mixednumericarray.sort() +"<br>")
document.write("<b>sorted with comparenumbers:</b> " + mixednumericarray.sort(comparenumbers) +"<br>")
</script>
stringarray: blue,humpback,beluga
sorted: beluga,blue,humpback
numberarray: 40,1,5,200
sorted without a compare function: 1,200,40,5
sorted with comparenumbers: 1,5,40,200
numericstringarray: 80,9,700
sorted without a compare function: 700,80,9
sorted with comparenumbers: 9,80,700
mixednumericarray: 80,9,700,40,1,5,200
sorted without a compare function: 1,200,40,5,700,80,9
sorted with comparenumbers: 1,5,9,40,80,200,700
stringname.split([separator])
separator specifies the character to use for separating the string. the separator is treated as a string. if separator is omitted, the array returned contains one element consisting of the entire string.
implemented in
navigator 3.0
description
the split method returns the new array.
examples
the following example defines a function that splits a string into an array of strings using the specified separator. after splitting the string, the function displays messages indicating the original string (before the split), the separator used, the number of elements in the array, and the individual array elements.function splitstring (stringtosplit,separator) {
this example produces the following output:
arrayofstrings = stringtosplit.split(separator)
document.write ('<p>the original string is: "' + stringtosplit + '"')
document.write ('<br>the separator is: "' + separator + '"')
document.write ("<br>the array has " + arrayofstrings.length + " elements: ")
for (var i=0; i < arrayofstrings.length; i++) {
document.write (arrayofstrings[i] + " / ")
}
}
var tempeststring="oh brave new world that has such people in it."
var monthstring="jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"
var space=" "
var comma=","
splitstring(tempeststring,space)
splitstring(tempeststring)
splitstring(monthstring,comma)the original string is: "oh brave new world that has such people in it."
the separator is: " "
the array has 10 elements: oh / brave / new / world / that / has / such / people / in / it. /
the original string is: "oh brave new world that has such people in it."
the separator is: "undefined"
the array has 1 elements: oh brave new world that has such people in it. /
the original string is: "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"
the separator is: ","
the array has 12 elements: jan / feb / mar / apr / may / jun / jul / aug / sep / oct / nov / dec /
see also
charat, indexof, lastindexof methods
math.sqrt(number)
implemented in
navigator 2.0
description
if the value of number is outside the required range, sqrt returns zero.
examples
the following function returns the square root of the variable x:function getroot(x) {
if you pass getroot the value nine, it returns three; if you pass it the value two, it returns 1.414213562373095.
return math.sqrt(x)
}
math.sqrt1_2
implemented in
navigator 2.0
tainted?
no
description
because sqrt1_2 is a constant, it is a read-only property of math.
examples
the following function returns one over the square root of two:function getroot1_2() {
return math.sqrt1_2
}
see also
e, ln2, ln10, log2e, log2e, pi, sqrt2 properties
math.sqrt2
implemented in
navigator 2.0
tainted?
no
description
because sqrt2 is a constant, it is a read-only property of math.
examples
the following function returns the square root of two:function getroot2() {
return math.sqrt2
}
see also
e, ln2, ln10, log2e, log2e, pi, sqrt1_2 properties
imagename.src
implemented in
navigator 3.0
tainted?
no
description
the src property initially reflects the src attribute of the <img> tag. setting the src property begins loading the new url into the image area (and aborts the transfer of any image data that is already loading into the same area). therefore, if you plan to alter the lowsrc property, you should do so before setting the src property. if the url in the src property references an image that is not the same size as the image cell it is loaded into, the source image is scaled to fit.beluga.gif
:<img name="myimage" src="beluga.gif" align="left">
if you set myimage.src='seaotter.gif'
, the image seaotter.gif
is scaled to fit in the same space originally used by beluga.gif
, even if seaotter.gif
is not the same size as beluga.gif
.
examples
the following example displays an image and three radio buttons. the user can click the radio buttons to choose which image is displayed. each image also uses the lowsrc property to display a low-resolution image.<script>
see also the examples for the image object.
function displayimage(lowres,highres) {
document.images[0].lowsrc=lowres
document.images[0].src=highres
}
</script>
<form name="imageform">
<b>choose an image:</b>
<br><input type="radio" name="imagechoice" value="image1" checked
onclick="displayimage('f15el.gif','f15e.gif')">f-15 eagle
<br><input type="radio" name="imagechoice" value="image2"
onclick="displayimage('f15e2l.gif','f15e2.gif')">f-15 eagle 2
<br><input type="radio" name="imagechoice" value="image3"
onclick="displayimage('ah64l.gif','ah64.gif')">ah-64 apache
<br>
<img name="aircraft" src="f15e.gif" lowsrc="f15el.gif" align="left" vspace="10"><br>
</form>
see also
complete, lowsrc properties
windowreference.status
implemented in
navigator 2.0
tainted?
yes
description
do not confuse the status property with the defaultstatus property. the defaultstatus property reflects the default message displayed in the status bar.
examples
suppose you have created a javascript function called pickrandomurl that lets you select a url at random. you can use the onclick event handler of an anchor to specify a value for the href attribute of the anchor dynamically, and the onmouseover event handler to specify a custom message for the window in the status property:<a href=""
in the preceding example, the status property of the window is assigned to the window's self property, as
onclick="this.href=pickrandomurl()"
onmouseover="self.status='pick a random url'; return true">
go!</a>self.status
. as this example shows, you must return true to set the status property in the onmouseover event handler.
see also
defaultstatus property
stringname.strike()
implemented in
navigator 2.0
description
use the strike 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 formatting of a string:var worldstring="hello, world"
the previous example produces the same output as the following html:
document.write(worldstring.blink())
document.write("<p>" + worldstring.bold())
document.write("<p>" + worldstring.italics())
document.write("<p>" + worldstring.strike())<blink>hello, world</blink>
<p><b>hello, world</b>
<p><i>hello, world</i>
<p><strike>hello, world</strike>
see also
blink, bold, italics methods
stringobjectname = new string(string)to use a string object:
1. stringname.propertyname
2. stringname.methodname(parameters)
string is any string.
stringname is the name of a string object or string variable.
propertyname is one of the properties listed below.
methodname is one of the methods listed below.
a string can be represented as a literal enclosed by single or double quotation marks; for example, "netscape" or 'netscape'.
property |
description
length
|
reflects the length of the string
|
prototype
|
lets you add properties to a string object.
| |
---|
methods
the string object has the following methods:
|
|
|
event handlers
none.
examples
example 1: string variable. the following statement creates a string variable:var last_name = "schaefer"
example 2: string object properties. the following statements evaluate to eight, "schaefer," and "schaefer":last_name.length
example 3: pass a string among scripts in different windows or frames. the following code creates two string variables and opens a second window:
last_name.touppercase()
last_name.tolowercase()var lastname = new string("schaefer")
if the html source for the second window (
var firstname = new string ("jesse")
empwindow=window.open('string2.html','window1','width=300,height=300')string2.html
) creates two string variables, emplastname and empfirstname, the following code in the first window assigns values to the second window's variables:empwindow.empfirstname=firstname
the following code in the first window displays the values of the second window's variables:
empwindow.emplastname=lastnamealert('empfirstname in empwindow is ' + empwindow.empfirstname)
alert('emplastname in empwindow is ' + empwindow.emplastname)
see also
text object, textarea object
stringname.sub()
implemented in
navigator 2.0
description
use the sub method with the write or writeln methods to format and display a string in a document.
examples
the following example uses the sub and sup methods to format a string:var supertext="superscript"
the previous example produces the same output as the following html:
var subtext="subscript"
document.write("this is what a " + supertext.sup() + " looks like.")
document.write("<p>this is what a " + subtext.sub() + " looks like.")this is what a <sup>superscript</sup> looks like.
<p>this is what a <sub>subscript</sub> looks like.
see also
sup method
formname.submit()
implemented in
navigator 2.0
description
the submit method submits the specified form. it performs the same action as a submit button.
the submit method fails without notice, if the form's action is a mailto:, news:, or snews: url. this is for security purposes. users can submit forms with such urls by clicking a submit button, but a confirming dialog will tell them that they are about to give away private or sensitive information.
examples
the following example submits a form called musicchoice:document.musicchoice.submit()
if musicchoice is the first form created, you also can submit it as follows:document.forms[0].submit()
see also the example for the form object.
see also
submit object, onsubmit event handler
<input
type="submit"
name="submitname"
value="buttontext"
[onblur="handlertext"]
[onclick="handlertext"]
[onfocus="handlertext"]>
value="buttontext" specifies the label to display on the button face. you can access this value using the value property.
1. submitname.propertyname
2. submitname.methodname(parameters)
3. formname.elements[index].propertyname
4. formname.elements[index].methodname(parameters)
formname is either the value of the name attribute of a form object or an element in the forms array.
index is an integer representing a submit object on a form or the name of a submit object as specified by the name attribute.
propertyname is one of the properties listed below.
methodname is one of the methods listed below.
a submit object is a form element and must be defined within a <form> tag.
clicking a submit button submits a form to the url specified by the form's action property. this action always loads a new page into the client; it may be the same as the current page, if the action so specifies or is not specified.
the submit button's onclick event handler cannot prevent a form from being submitted; instead, use the form's onsubmit event handler or use the submit method instead of a submit object. see the examples for the form object.
if a form contains only one element, a text object, then when the user enters a value and presses return, the form submits. (this is a standard html feature.)
property |
description
form property
|
specifies the form containing the submit object
|
name
|
reflects the name attribute
|
type
|
reflects the type attribute
|
value
|
reflects the value attribute
| |
---|
methods
the submit object has the following methods:
|
|
<input type="submit" name="submitbutton" value="done">see also the examples for the form object.
see also
button object, form object, reset object; submit method; onsubmit event handler
stringname.substring(indexa, indexb)
indexa is any integer from zero to stringname.length - 1, or a property of an existing object.
indexb is any integer from zero to stringname.length, or a property of an existing object.
implemented in
navigator 2.0
description
characters in a string are indexed from left to right. the index of the first character is zero, and the index of the last character is stringname.length - 1.
examples
example 1. the following example uses substring to display characters from the string "netscape":
var anystring="netscape"
//displays "net"
document.write(anystring.substring(0,3))
document.write(anystring.substring(3,0))
//displays "cap"
document.write(anystring.substring(4,7))
document.write(anystring.substring(7,4))
//displays "netscap"
document.write(anystring.substring(0,7))
//displays "netscape"
document.write(anystring.substring(0,8))
document.write(anystring.substring(0,10))
example 2. the following example replaces a substring within a string. it will replace both individual characters and substrings. the function call at the end of the example changes the string "brave new world" into "brave new web".function replacestring(olds,news,fulls) {
// replaces olds with news in the string fulls
for (var i=0; i<fulls.length; i++) {
if (fulls.substring(i,i+olds.length) == olds) {
fulls = fulls.substring(0,i)+news+fulls.substring(i+olds.length,fulls.length)
}
}
return fulls
}replacestring("world","web","brave new world")
navigator.mimetypes[index].suffixes
implemented in
navigator 3.0
tainted?
no
description
the suffixes property is a string consisting of each valid suffix (typically three letters long) separated by commas. for example, the suffixes for the "audio/x-midi" mime type are "mid, midi".
examples
see the examples for the mimetype object.
see also
description, enabledplugin, type properties
stringname.sup()
implemented in
navigator 2.0
description
use the sup method with the write or writeln methods to format and display a string in a document.
examples
the following example uses the sub and sup methods to format a string:var supertext="superscript"
the previous example produces the same output as the following html:
var subtext="subscript"
document.write("this is what a " + supertext.sup() + " looks like.")
document.write("<p>this is what a " + subtext.sub() + " looks like.")this is what a <sup>superscript</sup> looks like.
<p>this is what a <sub>subscript</sub> looks like.
see also
sub method