input (type="radio") | NN 2 IE 3 DOM 1 | |||||||||||||||||||||||||||||||||||
The radio object is a form control generated with an input element that has a type attribute set to "radio". radio objects related to each other are assigned the same name. This means all like-named radio objects become a collection (array) of radio objects. It may be necessary, therefore, to reference an individual radio button as an item in an array. The entire array, of course, has a length property you can use to assist in looping through all radio objects within the group, if necessary, to find which one is checked, and retrieve that object's value: |
||||||||||||||||||||||||||||||||||||
Properties and methods listed as follows are for individual radio buttons. |
||||||||||||||||||||||||||||||||||||
HTML Equivalent | ||||||||||||||||||||||||||||||||||||
<input type="radio"> |
||||||||||||||||||||||||||||||||||||
Object Model Reference | ||||||||||||||||||||||||||||||||||||
[window.]document.formName.elementName [window.]document.forms[i].elements[i] [window.]document.getElementById("elementID") |
||||||||||||||||||||||||||||||||||||
Object-Specific Properties | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
Object-Specific Methods | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
Object-Specific Event Handler Properties | ||||||||||||||||||||||||||||||||||||
|
checked | NN 2 IE 3 DOM 1 |
Read/Write | |
Determines whether the radio button is selected or turned on by the user or script. Only radio objects with the checked property set to true have their name/value pair submitted with the form. To find out whether the form element is set to be checked when the page loads, see the defaultChecked property. Scripts can change this property even if the element is disabled. |
|
Example | |
if (document.choiceForm.myRadio[0].checked) { //process first radio button } |
|
Value | |
Boolean: true | false. |
|
Default | |
false |
dataFld | NN n/a IE 4 DOM n/a |
Read/Write | |
Used with IE data binding to associate a remote data source column name to a radio button element value attribute determined by properties set in the object. A datasrc attribute must also be set for the element. Setting both the dataFld and dataSrc properties to empty strings breaks the binding between element and data source. Works only with text file data sources in IE 5/Mac. |
|
Example | |
document.myForm.myRadio[0].dataFld = "cableModem"; |
|
Value | |
Case-sensitive string identifier of the data source column. |
|
Default | |
None. |
dataSrc | NN n/a IE 4 DOM n/a |
Read/Write | |
Used with IE data binding to specify the ID of the page's object element that loads the data source object for remote data access. Content from the data source is specified via the datafld attribute. Setting both the dataFld and dataSrc properties to empty strings breaks the binding between element and data source. Works only with text file data sources in IE 5/Mac. |
|
Example | |
document.myForm.myRadio[0].dataSrc = "DBSRC3"; |
|
Value | |
Case-sensitive string identifier of the data source. |
|
Default | |
None. |
defaultChecked | NN 2 IE 3 DOM 1 |
Read/Write | |
Specifies whether element has the checked attribute set in the tag. You can compare the current checked property against defaultChecked to see if the state of the control has changed since the document loaded. Changing this property doesn't affect the current checked status. |
|
Example | |
var rBut = document.forms[0].myRadio[0]; if (rBut.checked != rBut.defaultChecked) { // process for changed state } |
|
Value | |
Boolean value: true | false. |
|
Default | |
Determined by HTML tag attribute. |
form | NN 2 IE 3 DOM 1 |
Read-only | |
Returns a reference to the form element that contains the current element (if any). When processing an event from this element, the event handler function automatically has access to the input element (as the event object's target or srcElement property). By reading the form property, the script can easily access other controls within the same form. |
|
Example | |
var theForm = evt.srcElement.form; |
|
Value | |
form element object reference. |
|
Default | |
None. |
name | NN 2 IE 3 DOM 1 |
Read/Write | |
This is the identifier associated with the form control. The value of this property is submitted as one-half of the name/value pair when the form is submitted to the server (the value property of the highlighted radio button supplies the value portion). Names are hidden from user view, since control labels are assigned via other means, depending on the control type. Form control names may also be used by script references to the objects. Assign the same name to every radio button in a group whose highlight/unhighlight characteristics are related. Despite the modern standards' preference for the id attribute, many browsers still require that a form control be assigned a name attribute to allow the control's value to be submitted, but no two elements should have the same id attribute value. Therefore, if scripts need to reference elements by id, devise two separate naming schemes for the common name attributes and unique id attributes. |
|
Example | |
document.orderForm.myRadio[0].name = "connectivity"; |
|
Value | |
Case-sensitive string identifier that follows the rules of identifier naming: it may contain no whitespace, can't begin with a numeral, and should avoid punctuation except for the underscore character. |
|
Default | |
None. |
status | NN n/a IE 4 DOM n/a |
Read/Write | |
Specifies whether the element is highlighted/checked. This property is identical to the checked property. |
|
Example | |
if (document.forms[0].myRadio[0].status) { ... } |
|
Value | |
Boolean value: true | false. |
|
Default | |
None. |
type | NN 3 IE 4 DOM 1 |
Read-only | |
Returns the type of form control element. The value is returned in all lowercase letters. It may be necessary to cycle through all form elements in search of specific types to do some processing on (e.g., emptying all form controls of type "text" while leaving other controls untouched). |
|
Example | |
if (document.forms[0].elements[3].type == "radio") { // process radio input type here } |
|
Value | |
Any of the following constants (as a string): button | checkbox | file | hidden | image | password | radio | reset | select-multiple | select-one | submit | text | textarea. |
|
Default | |
radio |
value | NN 2 IE 3 DOM 1 |
Read/Write | |
Indicates the current value associated with the form control that is submitted with the name/value pair for the group of like-named elements (if the particular radio button is selected). All values are strings, but they may represent other kinds of data, including Boolean and numeric values. |
|
Example | |
document.forms[0].myRadio[0].value = "56kbps"; |
|
Value | |
String. |
|
Default | |
None. |
handleEvent[ ] | NN |4| IE n/a DOM n/a |
handleEvent(event) | |
Instructs the object to accept and process the event whose specifications are passed as the parameter to the method. The object must have an event handler for the event type to process the event. Navigator 4 only |
|
Parameters | |
|
|
Returned Value | |
None. |