<INPUT
TYPE="radio"
NAME="radioName"
VALUE="buttonValue"
[CHECKED]
[onBlur="handlerText"]
[onClick="handlerText"]
[onFocus="handlerText"]>
textToDisplay
VALUE="buttonValue" specifies a value that is returned to the server when the radio button is selected and the form is submitted. This defaults to "on." You can access this value using the value property.
CHECKED specifies that the radio button is selected. You can access this value using the defaultChecked property.
textToDisplay specifies the label to display beside the radio button.
1. radioName[index1].propertyName
2. radioName[index1].methodName(parameters)
3. formName.elements[index2].propertyName
4. formName.elements[index2].methodName(parameters)
index1 is an integer representing a radio button in a Radio object.
formName is either the value of the NAME attribute of a Form object or an element in the forms array.
index2 is an integer representing a radio button on a form. The elements array contains an entry for each radio button in a Radio object.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
A Radio object is a form element and must be defined within a <FORM> tag.
All radio buttons in a radio button group use the same name property. To access the individual radio buttons in your code, follow the object name with an index starting from zero, one for each button the same way you would for an array such as forms:
document.forms[0].radioName[0]
is the first, document.forms[0].radioName[1]
is the second, and so on.
Methods
The Radio object has the following methods:
|
|
<INPUT TYPE="text" NAME="catalog" SIZE="20">Example 2. The following example contains a form with three text boxes and three radio buttons. The radio buttons let the user choose whether the text fields are converted to uppercase or lowercase, or not converted at all. Each text field has an onChange event handler that converts the field value depending on which radio button is checked. The radio buttons for uppercase and lowercase have onClick event handlers that convert all fields when the user clicks the radio button.
<INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b"
onClick="musicForm.catalog.value = 'soul-and-r&b'"> Soul and R&B
<INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz"
onClick="musicForm.catalog.value = 'jazz'"> Jazz
<INPUT TYPE="radio" NAME="musicChoice" VALUE="classical"
onClick="musicForm.catalog.value = 'classical'"> Classical
<HTML>See also the example for the Link object.
<HEAD>
<TITLE>Radio object example</TITLE>
</HEAD>
<SCRIPT>
function convertField(field) {
if (document.form1.conversion[0].checked) {
field.value = field.value.toUpperCase()}
else {
if (document.form1.conversion[1].checked) {
field.value = field.value.toLowerCase()}
}
}
function convertAllFields(caseChange) {
if (caseChange=="upper") {
document.form1.lastName.value = document.form1.lastName.value.toUpperCase()
document.form1.firstName.value = document.form1.firstName.value.toUpperCase()
document.form1.cityName.value = document.form1.cityName.value.toUpperCase()}
else {
document.form1.lastName.value = document.form1.lastName.value.toLowerCase()
document.form1.firstName.value = document.form1.firstName.value.toLowerCase()
document.form1.cityName.value = document.form1.cityName.value.toLowerCase()
}
}
</SCRIPT>
<BODY>
<FORM NAME="form1">
<B>Last name:</B>
<INPUT TYPE="text" NAME="lastName" SIZE=20 onChange="convertField(this)">
<BR><B>First name:</B>
<INPUT TYPE="text" NAME="firstName" SIZE=20 onChange="convertField(this)">
<BR><B>City:</B>
<INPUT TYPE="text" NAME="cityName" SIZE=20 onChange="convertField(this)">
<P><B>Convert values to:</B>
<BR><INPUT TYPE="radio" NAME="conversion" VALUE="upper"
onClick="if (this.checked) {convertAllFields('upper')}"> Upper case
<BR><INPUT TYPE="radio" NAME="conversion" VALUE="lower"
onClick="if (this.checked) {convertAllFields('lower')}"> Lower case
<BR><INPUT TYPE="radio" NAME="conversion" VALUE="noChange"> No conversion
</FORM>
</BODY>
</HTML>
See also
Checkbox object, Form object, Select object
Math.random()
//Returns a random number between 0 and 1
function getRandom() {
return Math.random()
}
document.referrer
Implemented in
Navigator 2.0
Tainted?
Yes
Description
When a user navigates to a destination document by clicking a Link object on a source document, the referrer property contains the URL of the source document. Evaluate the referrer property from the destination document.
Examples
In the following example, the getReferrer function is called from the destination document. It returns the URL of the source document.function getReferrer() {
return document.referrer
}
navigator.plugins.refresh([true|false])
false refreshes the plugins array to make newly installed plug-ins available, but does not reload open documents.
Implemented in
Navigator 3.0
Description
The refresh method makes newly installed plug-ins available by updating related arrays such as the plugins array. If the true keyword is specified, refresh reloads all open documents that contain plug-ins.
Examples
The following code refreshes arrays and reloads open documents containing embedded objects:navigator.plugins.refresh(true)
See also
go, reload, replace methods
location.reload([true])
Implemented in
Navigator 3.0
Description
The reload method forces a reload of the document specified by the URL in the location.href property.window.location.reload()
instead of simply using location.reload()
. 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
.
Examples
The following example displays an image and three radio buttons. The user can click the radio buttons to choose which image is displayed. Clicking another button lets the user reload the document.<SCRIPT>
function displayImage(theImage) {
document.images[0].src=theImage
}
</SCRIPT>
<FORM NAME="imageForm">
<B>Choose an image:</B>
<BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image1" CHECKED
onClick="displayImage('seaotter.gif')">Sea otter
<BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image2"
onClick="displayImage('orca.gif')">Killer whale
<BR><INPUT TYPE="radio" NAME="imageChoice" VALUE="image3"
onClick="displayImage('humpback.gif')">Humpback whale
<BR>
<IMG NAME="marineMammal" SRC="seaotter.gif" ALIGN="left" VSPACE="10">
<P><INPUT TYPE="button" VALUE="Click here to reload"
onClick="window.location.reload()">
</FORM>
See also
go, refresh, replace methods
location.replace("URL")
Implemented in
Navigator 3.0
Description
The replace method loads the specified URL over the current history entry, so after the replace method is used, the user cannot navigate to the previous URL by using Navigator's Back button.window.location.replace()
instead of simply using location.replace()
. 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
.if (location.replace == null)
The replace method does not create a new entry in the history list. To create an entry in the history list while loading a URL, use go.
location.replace = location.assign
Examples
The following example lets the user choose among several catalogs to display. The example displays two sets of radio buttons which let the user choose a season and a category, for example the Spring/Summer Clothing catalog or the Fall/Winter Home & Garden catalog. When the user clicks the Go button, the displayCatalog function executes the replace method, replacing the current URL with the URL appropriate for the catalog the user has chosen. Note that after the replace method is used, the user cannot navigate to the previous URL (the list of catalogs) by using Navigator's Back button.<SCRIPT>
function displayCatalog() {
var seaName=""
var catName=""
for (var i=0; i < document.catalogForm.season.length; i++) {
if (document.catalogForm.season[i].checked) {
seaName=document.catalogForm.season[i].value
i=document.catalogForm.season.length
}
}
for (var i in document.catalogForm.category) {
if (document.catalogForm.category[i].checked) {
catName=document.catalogForm.category[i].value
i=document.catalogForm.category.length
}
}
fileName=seaName + catName + ".html"
location.replace(fileName)
}
</SCRIPT>
<FORM NAME="catalogForm">
<B>Which catalog do you want to see?</B>
<P><B>Season</B>
<BR><INPUT TYPE="radio" NAME="season" VALUE="q1" CHECKED>Spring/Summer
<BR><INPUT TYPE="radio" NAME="season" VALUE="q3">Fall/Winter
<P><B>Category</B>
<BR><INPUT TYPE="radio" NAME="category" VALUE="clo" CHECKED>Clothing
<BR><INPUT TYPE="radio" NAME="category" VALUE="lin">Linens
<BR><INPUT TYPE="radio" NAME="category" VALUE="hom">Home & Garden
<P><INPUT TYPE="button" VALUE="Go" onClick="displayCatalog()">
</FORM>
See also
history object; "replace" parameter of open (document object) method; go, refresh, reload methods
formName.reset()
Implemented in
Navigator 3.0
Description
The reset method restores a form element's default values. A reset button does not need to be defined for the form.
Examples
The following example displays a Text object in which the user is to type "CA" or "AZ". The Text object's onChange event handler calls a function that executes the form's reset method if the user provides incorrect input. When the reset method executes, defaults are restored and the form's onReset event handler displays a message.<SCRIPT>
function verifyInput(textObject) {
if (textObject.value == 'CA' || textObject.value == 'AZ') {
alert('Nice input')
}
else { document.form1.reset() }
}
</SCRIPT>
<FORM NAME="form1" onReset="alert('Please enter CA or AZ.')">
Enter CA or AZ:
<INPUT TYPE="text" NAME="state" SIZE="2" onChange=verifyInput(this)><P>
</FORM>
See also
onReset event handler, Reset object
<INPUT
TYPE="reset"
NAME="resetName"
VALUE="buttonText"
[onBlur="handlerText"]
[onClick="handlerText"]
[onFocus="handlerText"]>
VALUE="buttonText" specifies the text to display on the button face. You can access this value using the value property.
1. resetName.propertyName
2. resetName.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 Reset object on a form or the name of a Reset object as specified by the NAME attribute.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
A Reset object is a form element and must be defined within a <FORM> tag.
The reset button's onClick event handler cannot prevent a form from being reset; once the button is clicked, the reset cannot be canceled.
Property |
Description
form property
|
Specifies the form containing the Reset object
|
name
|
Reflects the NAME attribute
|
type
|
Reflects the TYPE attribute
|
value
|
Reflects the VALUE attribute
| |
---|
Methods
The Reset object has the following methods:
|
|
<B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2">Example 2. The following example displays two Text objects, a Select object, and three radio buttons; all of these objects have default values. The form also has a reset button with the text "Defaults" on its face. If the user changes the value of any of the objects and then clicks the Defaults button, the original values are restored.
<P><INPUT TYPE="reset" VALUE="Clear Form">
<HTML>
<HEAD>
<TITLE>Reset object example</TITLE>
</HEAD>
<BODY>
<FORM NAME="form1">
<BR><B>City: </B><INPUT TYPE="text" NAME="city" VALUE="Santa Cruz" SIZE="20">
<B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2">
<P><SELECT NAME="colorChoice">
<OPTION SELECTED> Blue
<OPTION> Yellow
<OPTION> Green
<OPTION> Red
</SELECT>
<P><INPUT TYPE="radio" NAME="musicChoice" VALUE="soul-and-r&b"
CHECKED> Soul and R&B
<BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="jazz">
Jazz
<BR><INPUT TYPE="radio" NAME="musicChoice" VALUE="classical">
Classical
<P><INPUT TYPE="reset" VALUE="Defaults" NAME="reset1">
</FORM>
</BODY>
</HTML>
arrayName.reverse()
Implemented in
Navigator 3.0
Description
The reverse method transposes the elements of the calling array object.
Examples
The following example creates an array myArray, containing three elements, then reverses the array.myArray = new Array("one", "two", "three")
This code changes myArray so that:
myArray.reverse()
Math.round(number)
Implemented in
Navigator 2.0
Description
If the fractional portion of number is .5 or greater, the argument is rounded to the next highest integer. If the fractional portion of number is less than .5, the argument is rounded to the next lowest integer.
Examples
//Displays the value 20
document.write("The rounded value is " + Math.round(20.49))
//Displays the value 21
document.write("<P>The rounded value is " + Math.round(20.5))
//Displays the value -20
document.write("<P>The rounded value is " + Math.round(-20.5))
//Displays the value -21
document.write("<P>The rounded value is " + Math.round(-20.51))