I would like to show an alert if no check box was checked in a field.
The idea is that at least one check box should be checked.
I usually work with PHP so sadly don't have some basic JS principles down.
This is all I want to accomplish--I've seen many posts on this topic but they are usually beyond what I need.
Guys you can do this kind of validation very easily.
Just you have to track the id or name of the checkboxes. For statically you can use hard coded id of the checkboxes and for dynamically you can use the name of the field as an array and create a loop.
Here you can see screen captures from Firefox and Chrome: Text alert messages are generated entirely by the browser and will even translate automatically into different languages - something that would be almost impossible using just Java Script. I'm not sure if this detail is enforced in all browsers though.Of course, if you want better support than that, you could get all checkboxes, loop through them and check if they have the class, then see if there's more than one checked.Adding HTML5 validation to the checkbox is actually very simple.All you need to do is include a This tells the browser that the form should not be allowed to submit without the checkbox checked.