Validating radiobutton


26-Jul-2015 19:38

At that time this was the only way to do the validation.

Since then developments in Java Script have introduced ways to perform radio button validation in far less obtrusive ways however the less obtrusive code is slightly more complicated and has a significant overhead if you do not use that approach for all of your field validations (as you ought to).

Well here we have a form containing three radio buttons to show you how to do it. Note that the highlighted parts of this code will be referenced within the validation javascript, you can call them what you like but you must name fields consistently (ie.

all fields shown highlighted here and in the javascript with the same name must still all have the same name if you rename them.

When a button is selected, the value of the my Option field will contain the number of the button selected.

The name field determines which group that a particular button belongs to.Here is the code used for the radio button themselves.The creation of multiple groups of radio buttons for the one form is also straightforward.In this instance for the purpose of illustration, we simply display an alert advising which button was selected (shown in italics).

It should be a relatively simple matter for you to take the above form field definitions and javascript and incorporate it into your form.There browsers, however, are often not smart enough to recognize the nesting, so it is worth putting them in to maximize the number of browsers in which the code will function.