57 of 133 menu

Radio switch

A radio button is an HTML form element in the form of a round button that can be checked or unchecked.

The radio button is created using the tag input with the attribute type in the value radio. Appearance:

A single radio switch is almost never used, they should be used in a group. However, only one radio switch in a group can be checked. The switches will form a group only if they have the same attribute value name (see examples below).

Example

Let's make two radio switches: the first one is checked (we'll set the attribute checked), and the second one is not. In this case, the switches will be a group in which only one of them can be checked (since they have the same attribute value name).

Note that these radio buttons are given different values ​​for the attribute value. This is necessary so that after sending the data to the server, PHP can determine which of the radio buttons was selected:

<input type="radio" name="test" checked value="1"> <input type="radio" name="test" value="2">

:

Example

Now let's make two groups of radio switches: the first group will have one attribute value name, and the second - another. Let's try clicking on them, and we'll see that the groups switch independently of each other:

<input type="radio" name="radio1" checked> <input type="radio" name="radio1"> <input type="radio" name="radio1"> <br> <input type="radio" name="radio2" checked> <input type="radio" name="radio2"> <input type="radio" name="radio2">

:

See also

  • checkbox,
    with which you can implement a flag
  • attribute checked,
    which makes the radio switch marked
  • pseudo class checked,
    which sets styles for the marked radios
  • attribute disabled,
    which blocks form elements
  • tag label,
    which sets the prompt for the radio
byenru