?
Solved

validate checkboxes and radio buttons

Posted on 2009-07-13
6
Medium Priority
?
443 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
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 

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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

777 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