Link to home
Start Free TrialLog in
Avatar of PhotoMan2000
PhotoMan2000

asked on

validate checkboxes and radio buttons

I have 2 groups of check boxes and 2 groups of radio boxes that need to be validate for being selected / checkes.

For the checkoxes, the user must pic at least one box on each group. name
For the radio buttons, the user must select one radio button.

Each checkboxes and radio buttons are grouped by matching names.

I do NOT want an alert to fire but make use of the .error  that gets attach when I'm using this style code:


$("#FORMNAME").validate(
rules {
 fieldname: "required"
},
messages{
 fieldname: "This is Required"
}

Open in new window

Avatar of strickdd
strickdd
Flag of United States of America image

This page shows you how to loop through the Checkboxes/Radio Buttons. All you need to do is set a flag if one is checked. If that flag is set it is valid, if not it is invalid

http://www.randomsnippets.com/2008/05/15/how-to-loop-through-checkboxes-or-radio-button-groups-via-javascript/
Avatar of PhotoMan2000
PhotoMan2000

ASKER

I apologize.. I want to use JQUERY for the solution. (If not buttons or boxes are check to add the message next to the element group that is invalid.
Yep, saw that.. can't seem to figure it out, which is why I'm asking for help in EE.
Sorry, that's not working for me.  In my original code snippet that method, inserts a div element with a class of "error" at each item that is in the rules list using the Message values.

The sample that you provided, (which I had seen before but gave another chance) has a label called "error" already part of the code.  So when I first load the page the error message is present BEFORE submitting the form to be validated

Also I'm using coldfusion so an attribute in the input tag of validate="required:true" throws an error as it's not correct for coldfusion.

Please advise..

ASKER CERTIFIED SOLUTION
Avatar of PhotoMan2000
PhotoMan2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial