Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5952239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:39:12+00:00 2026-05-22T17:39:12+00:00

I’m using jQuery validation to validate a form with a radio button set on

  • 0

I’m using jQuery validation to validate a form with a radio button set on it (set = two radio buttons for this example). The radio buttons with labels are below. The form is on a jQueryUI dialog.

<input type="radio" name="chooseMe" value="Yes" id="radio_yes" /><label for="radio_yes">Yes</label>
<input type="radio" name="chooseMe" value="No" id="radio_no" /><label for="radio_no">No</label>

I grabbed the highlight/unhighlight code from the validation plugin page on jquery.com
http://docs.jquery.com/Plugins/Validation/validate
(go to the “Options” tab and search for “unhighlight”)

highlight: function (element, errorClass, validClass) {
    $(element).addClass(errorClass).removeClass(validClass);
    $(element.form).find("label[for=" + element.id + "]").addClass(errorClass);
},
unhighlight: function (element, errorClass, validClass) {
    $(element).removeClass(errorClass).addClass(validClass);
    $(element.form).find("label[for=" + element.id + "]").removeClass(errorClass);
},

The first problem i’m having is when validated as required, only the “Yes” label is highlighted.
The second problem is if I don’t resolve the validation issue and cancel out of the jQueryUI dialog, then come back into the dialog, the “Yes” label disappears completely.

To resolve the first issue, what i want to do is highlight both the “Yes” and “No” labels. So, working on the highlight code, i would need to get the name of the input (“chooseMe”) from the element id, then from that name, for all the id’s associated with that name (“radio_yes” and “radio_no”), highlight all the labels. Of course, then there’s the converse for the unhighlight code.

Since i have several radio button sets in the form, i need this to be generic (no hardcoding “chooseMe”, etc.)

Does that sound reasonable? If so, the only problem is i don’t know how to do that 🙂

Thanks in advance.

jsFiddle as requested:
http://jsfiddle.net/Bd688/4/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:39:13+00:00Added an answer on May 22, 2026 at 5:39 pm

    Ok, this iteration of the jsfiddle highlights both labels:

    http://jsfiddle.net/Bd688/6/

    The idea is to get the name of the element and look for all the other elements of the same name, then apply the same code you were applying. So I just changed this:

    $(element.form).find('[name='+element.name+']').each(function (i, sameName){
       $(element.form).find("label[for=" + sameName.id + "]").removeClass(errorClass); 
    });
    

    EDIT: Ok, so it turns out jQuery.validate doesn’t really like you using its errorClass and applying it to labels. I made another class and it seems to be working:

    http://jsfiddle.net/Bd688/7/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.