Validating radio button checked

posted by | Leave a comment

Hi I was just wondering how to prompt an error if no radio button is selected?I am adding a lot of entries into a listview and I have it so you can select either Fixed or Zero (working with bonds) and I want that if neither is selected, a messagebox shows up.And I know my HTML isn't valid, but unless it directly affects my current problem then I'll handle it later.In addition to the Javascript solutions above, you can also use an HTML 5 solution by marking the radio buttons as required in the markup.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.This will eliminate the need for any Javascript and let the browser do the work for you.

The solution here is to give all of the radio buttons within the group the same name but different values.

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.

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.

Leave a Reply

Totally free adult sexhookups