Radio buttons — alternative method

This program shows how to change an HTML image with an HTML radio button group by an alternative method.

Programming Issues

In our previous example we changed our image via a radio button group by passing different arguments to the changeImage() function depending on which radio button was clicked. There is an alternative method of doing this which is useful when reading from a radio button group in response to a different event (e.g. a push button being clicked).

We can reference the individual buttons in a group using form.radSel[n], and see which one is checked by testing whether form.radSel[n].checked is true. Note that there is no equivalent of selectedIndex for radio buttons - we have to test each one individually.

We will see this method in action again in our comprehensive basic forms example.

Demonstration

[image]

Source and Downloads