<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.
| Property | Description |
|---|---|
| checked | Lets you programmatically select a radio button |
| defaultChecked | Reflects the CHECKED attribute |
| form property | Specifies the form containing the Radio object |
| length | Reflects the number of radio buttons in a Radio object |
| name | Reflects the NAME attribute |
| type | Reflects the TYPE attribute |
| value | Reflects the VALUE attribute |
|
|
|
<INPUT TYPE="text" NAME="catalog" SIZE="20"> <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'"> ClassicalExample 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.
<HTML>
<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 the example for the
Link object.
Math.random()
//Returns a random number between 0 and 1
function getRandom() {
return Math.random()
}
document.referrer
If the user clicked on a link to get to the current URL, referrer contains the URL the user linked from. referrer is empty if the user typed a URL in the Location box, or used some other means to get to the current URL. referrer is also empty if the server does not provide environment variable information.
referrer is a read-only property.
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.
When the user installs a plug-in, that plug-in is not available until refresh is called or the user closes and restarts Navigator.
navigator.plugins.refresh(true)
location.reload([true])
This method uses the same policy that the Navigator's Reload button uses (Once per Session, Every Time, or Never). The user sets the default value of this policy by choosing Network Preferences from the Options menu and specifying Verify Documents on the Cache tab of the Preferences dialog box.
The reload method does not force a transaction with the server, unless the user has set the preference to Every Time, in which case it does a "conditional GET" request using an If-modified-since HTTP header, to ask the server to return the document only if its last-modified time is newer than the time the client keeps in its cache. In other words, reload will reload from the cache, unless the user has specified Every Time and the document has changed on the server since it was last loaded and saved in the cache.
In event handlers, you must specify 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.
<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>
location.replace("URL")
In event handlers, you must specify 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 your program will be run with JavaScript in Navigator 2.0, you could put the following line in a <SCRIPT> tag early in your program. This emulates replace, which was introduced in Navigator 3.0:
if (location.replace == null) location.replace = location.assignThe 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.
<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>
formName.reset()
<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>
<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 |
|
|
|
<B>State: </B><INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> <P><INPUT TYPE="reset" VALUE="Clear Form">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.
<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()
myArray = new Array("one", "two", "three")
myArray.reverse()
This code changes myArray
so that:
Math.round(number)
//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))