<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.
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.
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.
|
|
<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>
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.
<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 (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
<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.
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.
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">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()
myArray = new Array("one", "two", "three")This code changes myArray so that:
myArray.reverse()
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))