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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:26:25+00:00 2026-06-08T19:26:25+00:00

The JQuery validator plugin uses the name and I would like to find it

  • 0

The JQuery validator plugin uses the “name” and I would like to find it dynamically by ID. My $test variable returns a string with the correct name but then I can’t use a string.

How can I use this variable to replace the hard coded name (ctl00$MainContent$ListBox1)?

Instead of:

<script type="text/javascript">
    $(document).ready(function () {
        var $test = $("#ListBox1").attr("name");

        $("#form1").validate({
            rules: {
                ctl00$MainContent$ListBox1: {
                    required: true,
                    rangelength: [0, 4]
                }
            },
            messages: {
                ctl00$MainContent$ListBox1: {
                    required: "Please select a state",
                    rangelength: "Please select maximum 4 states"
                }
            },
            errorLabelContainer: $("#message")
        });
    });
</script>

I would like to use something like:

$("#form1").validate({
     rules: {
         $test: {
              required: true,
              rangelength: [0, 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-06-08T19:26:26+00:00Added an answer on June 8, 2026 at 7:26 pm

    You can’t actually replace a member id. You can however augment objects:

    $(document).ready(function () {
        var test = $("#ListBox1").attr("name");
        var validators = {
            rules: {},
            messages: {},
            errorLabelContainer: $("#message")
        };
    
        validators.rules[test] = {
            required: true,
            rangelength: [0, 4]
        };
        validator.messages[test] = {
            required: "Please select a state",
            rangelength: "Please select maximum 4 states"
        }
    
        $("#form1").validate(validators);
    });
    

    Now your messages and rules object both contain a member with your saved name.

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

Sidebar

Related Questions

We have a form which uses the JQuery Validation Plugin and would like to
I'm working on a legacy groovy project that uses jQuery's password strength validator plugin
I'm using the jQuery validate plugin, and would like to return a random value
I've created a method for jquery's validator plugin, that works like the remote rule.
I would really like use the jQuery Validation plugin in my ASP.NET Web Forms
I'm using jQuery with the validators plugin. I would like to replace the required
hi i am using jquery validator plugin , i saw annnotation like this |=
I'm keen to use the jQuery validator plugin to validate my code, but I
I'm currently creating a form validation script based on the jQuery validator plugin .
All, I am trying to use JQuery's URL Validator plugin. http://docs.jquery.com/Plugins/Validation/Methods/url I have a

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.