Javascript code for validating radio buttons

I know there might be lot of duplicates, but I've tried them all to no avail.

I'm creating a pay request form where the user will select how they want to be paid for overtime worked.

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.

This will eliminate the need for any Javascript and let the browser do the work for you.

if I select "no", the second option of the radio, it does not work correctly, show me an error message when it should not if I select "Yes" the first option of the radio, it works as expected.

How do I get Java Script to grab all the radios in the group, check if any in that group are checked ? Function that gathers fields that need to be examined: *I can't use the specific name because several clients use the app so the ids and names, will be different.

And I know my HTML isn't valid, but unless it directly affects my current problem then I'll handle it later.

I would change the line if (radios[i].checked) form Valid = true; to if (radios[i].checked) so it becomes true with the value of the checked item. Also, always use braces, even if there is just one item.

I created the following form: I implemented a validation script that works for many of the form elements but for some reason it's not working for the radio buttons so currently a user can submit the form without selecting one of the required radio buttons.

How can I enable validation for the radio buttons using this existing script? attribute and that would make sure something is there.

The two choices are 'pay' (user receives extra pay in their paycheck), or 'time' (user receives compensatory time-off to be taken at a later date).

Tags: , ,