JavaScript Radio Object

The JavaScript Radio object is a property of the form object. Radio button FORM syntax is:

<FORM>
<INPUT TYPE="radio" NAME="timeofDay" VALUE="Morning" CHECKED onClick="clickFunction">Morning
<INPUT TYPE="radio" NAME="timeofDay" VALUE="Afternoon" onClick="clickFunction">Afternoon
<INPUT TYPE="radio" NAME="timeofDay" VALUE="Evening" onClick="clickFunction">Evening
</FORM>

Here's how it looks:

Morning Afternoon Evening

The button belongs to the timeofDay of buttons and only one in that group should be checked. The clickFunction is run when the button is clicked and must exist as a function, usually in the header. The value is the value for the group name returned when the button is checked. The option "CHECKED" sets the button so it is selected when it is initially displayed. Both the onClick and CHECKED parameters are optional. Type, name, and value are required. If the onClick statement is not used to set the click function, a default click function is used by the system to set the radio buttons as they are clicked.

Properties

  • checked - The value is true when the button is checked.
  • defaultChecked - Is true if the button is checked by default.
  • form - The form object that includes the radio button.
  • name - The name of the radio button.
  • type - The type of element which is radio.
  • value - The value of the button.

Methods

  • blur() - Takes the focus away from the radio button.
  • click() - This function acts as if the user clicked the button.
  • focus() - Gives the focus to the radio button.

Events

  • onBlur
  • onClick
  • onFocus