Solved

validate checkboxes and radio buttons

Posted on 2009-07-13
6
431 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

706 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