Validating radio button checked
Before getting into the additional validation scripting, I want you to notice something about the found_it variable in the original script - it is declared but not initialized. Because it was not assigned a value initially, it has an original value of null, and will stay that way unless its value is reset to a checked button's value. Logical operators test two boolean values for equality.
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.