An HTML combobox shows a dropdown list of items from which one item is selected.
By default the caption for that list is the first item.
In actual fact the setup of these fields is the most simple of all form fields to validate as radio buttons set one value that only needs to be tested when the form is submitted.
The difficulty with radio buttons is that there are at least two and usually more fields that need to be placed on the form, related together and tested as one group.
In this example, we alert the user to please check a radio button.
If our form was actually wired to a CGI script on the server, or set to some other action, we could also return false to the onsubmit handler to keep the form from submitting as demonstrated in the Stop That Form example.
To check for the possibility of the user leaving the entire group unchecked, an additional if statement only needs to test the variable "found_it" for a value of null. Remember - comparison operators compare two operands for equality. The not operator evaluates a null value in the same way it evaluates a false value, so it can be used to test found_it to see if it has been assigned a value.
The if/else can be constructed in two different ways using two different operators. To keep from becoming confused by the not operator, just think of it as a shorthand way of saying, "found_it==false".
Although I've used radio buttons in the last few examples, the same concepts can be applied to checkbox groups as well.
Validating Radio Button Groups By setting the value of the variable, "found_it" equal to the checked button's value, the original button loop script can easily find which button was checked. We need a way to handle this situation, especially if you want to require a button from a group be checked.