Solved

validate checkboxes and radio buttons

Posted on 2009-07-13
6
432 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:PhotoMan2000
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 24842233
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/
0
 

Author Comment

by:PhotoMan2000
ID: 24842280
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.
0
 
LVL 28

Expert Comment

by:strickdd
ID: 24842469
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:PhotoMan2000
ID: 24843047
Yep, saw that.. can't seem to figure it out, which is why I'm asking for help in EE.
0
 

Author Comment

by:PhotoMan2000
ID: 24850122
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..

0
 

Accepted Solution

by:
PhotoMan2000 earned 0 total points
ID: 25005632
This ended up working.


fieldname: "required",

fieldname: {

    required: function(element){ return $("input=[name='otherfieldname'][value='Other']").is(':checked'); },

},		

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now