AvailabilityJavaScript 1.0; enhanced in JavaScript 1.1 Inherits from/OverridesInherits from Input, HTMLElement SynopsisThe Radio button element is usually used in groups of mutually exclusive options that have the same name. To reference one Radio element within a group, use this syntax: form.radio_name[j] form.radio_name.length PropertiesRadio inherits properties from Input and HTMLElement and defines or overrides the following:
MethodsRadio inherits methods from Input and HTMLElement. Event HandlersRadio inherits event handlers from Input and HTMLElement and defines or overrides the following:
HTML SyntaxA Radio element is created with a standard HTML <input> tag. Radio elements are created in groups by specifying multiple <input> tags that have the same name attribute: <form> ... <input type="radio" // Specifies that this is a radio button [ name="name" ] // A name you can use later to refer to this button // or to the group of buttons with this name // Specifies the name property [ value="value" ] // The value returned when this button is selected // Specifies the value property [ checked ] // Specifies that the button is initially checked // Specifies the defaultChecked property [ onclick="handler" ] // JavaScript statements to be executed when the button // is clicked > label // The HTML text that should appear next to the button ... </form> DescriptionThe Radio element represents a single graphical radio button in an HTML form. A radio button is one button in a group of buttons that represents mutually exclusive choices. When one button is selected, the previously selected button is deselected. The onclick event handler allows you to specify JavaScript code to be executed when the button is selected. You can examine the checked property to determine the state of the button and set this property to select or deselect the button. Note that setting checked changes the graphical appearance of the button but does not invoke the onclick event handler. The initial value of the checked property and the value of the defaultChecked property are determined by the checked attribute. Only one Radio element in a group may contain this attribute -- it sets the checked and defaultChecked properties true for that element and false for all other radio buttons in the group. If none of the elements has the checked attribute, the first one in the group is checked (and defaultChecked) by default. Note that the text that appears next to a radio button is not part of the Radio element itself and must be specified externally to the Radio's HTML <input> tag. Radio elements are used in groups of mutually exclusive options. A mutually exclusive group is defined as the set of all Radio elements within a form that have the same name. If the shared name of a group of Radio elements in form f is opts, f.opts is an array of Radio elements, and f.opts.length is the number of elements in the array. You can set the value attribute or the value property of a Radio element to specify the string that is passed to the server if the Radio element is checked when the form is submitted. Each Radio element in a group should specify a distinct value so a script on the server can determine which one was checked when the form was submitted. UsageRadio elements can present the user with a list of multiple mutually-exclusive options. Use the Checkbox element to present a single option or a list of options that are not mutually exclusive. See AlsoCheckbox, Form, Input; HTMLInputElement in DOM reference section |