Solved

validate checkboxes and radio buttons

Posted on 2009-07-13
6
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

689 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