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 8615739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:27:14+00:00 2026-06-12T05:27:14+00:00

I have a form that i’m trying to use the jquery validate plugin. My

  • 0

I have a form that i’m trying to use the jquery validate plugin. My problem is that i can’t access the label in the success callback. I can get label.attr('for'), but when i try label.attr('id'), or label.html(), i get undefined.

Here’s my validate call:

    <script type="text/javascript">
        $(document).ready(function() {
            $('#personal_info').validate({
                rules: {
                    LastName: "required",
                    Age: "required"
                },
                messages: {
                    LastName: "",
                    Age: ""
                },
                errorPlacement: function(error, element) {
                    console.log('element.attr = '+element.attr('name'));
                    if(element.attr('name') == 'Age') {
                            console.log('element = '+element.parents().siblings('label').html());
                            element.parents().siblings('label').removeClass('highlight').addClass('warning');
                    }                                       
                    //error.insertBefore(element.parent().children("br"));
                },

                // specifying a submitHandler prevents the default submit, good for the demo
                submitHandler: function() {
                    document.personal_info.submit();
                },
                validClass: "checkmark",
                // set this class to error-labels to indicate valid fields
                success: function(label) {
                    console.log('the label for = '+label.attr('for'));
                    console.log('the label id = '+label.attr('id'));
                }   
            });
        });
</script>

Here’s a piece of my html:

<label for="Age" id="age18" class="highlight">&nbsp;&nbsp;&nbsp;&nbsp;Are you at least 18 years of age?</label>
       <table id="OnlineAppWizard_InputAge18" border="0">
             <tr>
                 <td>
                     <input id="Age18_yes" type="radio" name="Age" value="Yes"  <?
                         if ($Age18 == "Yes") {
                               print "checked";
                         }
                      ?>/>
                     <label for="Age18_yes">Yes</label>
                 </td>
                 <td>
                     <input id="Age18_no" type="radio" name="Age" value="No" <?
                         if ($Age18 == "No") {
                                print "checked";
                         } ?>/>
                     <label for="Age18_no">No</label>
                 </td>
             </tr>
         </table>

When i click on one of the radio buttons, this is what appears in the firebug console:the

the label for = Age
the label id = undefined

You can see from the html snippet that the label tag with the “for” attribute of “Age”, also has an “id” attribute of “age18”

  • 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-06-12T05:27:15+00:00Added an answer on June 12, 2026 at 5:27 am

    The label parameter passed to the success callback is not the label you think it is. The jQuery Validation plugin generates error labels for each element to display error messages. It is this generated label that is passed to the success callback. You can see this by adding console.log(label); as the first line of the callback. It will return the following:

    [<label for=​"Age" generated=​"true" class=​"error" style=​"display:​ inline;​ ">​</label>​]
    

    FYI, that label is created in the showLabel method of the validator. It is also the same element that is passed as the error parameter of the errorPlacement method. Generally, the error element would be appended to the form element that caused the error (i.e., failed to validate).

    To access the original label from the success callback, you will need a more direct approach.

    One solution, and very specific to this particular label, is to simply access it by it’s ID, e.g.

    if(label.attr('for') === 'Age') {
        $('#age18')...    // do something to the label
    }
    

    A more generic solution would be:

    $('#personal_info').children('[for="' + label.attr('for') + '"]')...  // do something to label
    

    I have included both solutions in the live demo linked below.

    Live Demo

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

Sidebar

Related Questions

I have a form that is using jQuery Validate plugin for client side validation,
I have a form that I am trying to post to php using jQuery
I have a form that has label values that I would like to pass
I have a form that I want to validate before the user is able
I have a form that looks like so: <label for=fullpath><span class=required>*Full Path of folder
I' have form that user can select a color. I'm writing that color to
I have a form that i am trying to submit after the page loads
I have a form that uses jQuery to submit an ajax post and it
I have a form that has MenuScripts (top-levels and second-levels). The problem that I
I have a form that use a control with the attribute multiple=multitple. This allow

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.