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

  • SEARCH
  • Home
  • 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 346045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:08:26+00:00 2026-05-12T11:08:26+00:00

I am trying to clean up some of the JavaScript throughout my views and

  • 0

I am trying to clean up some of the JavaScript throughout my views and one of the things I would like to do is move my jQuery Validation code to an external script function and pass in references to the fields I need to process/validate. The issue I am facing is pertaining to how the signature of jQuery Validate’s rules field is formatted:

$("#form").validate({
    rules: {
        txtNoSpam: {
            remote: WebSettings.SpamFilterValidationUrl
        }
    },
    messages: {
        txtNoSpam: {
            remote: "Answer is incorrect."
        }
    },
});

In the above code ‘txtNoSpam’ maps directly to an element on my page called txtNoSpam, but I would much rather pass txtNoSpam into my initialization function as an object and then map the validation to the correct field using the supplied object’s element name as the parameter name:

function Init(form, field1)
    form.validate({
        rules: {
            field1.attr('name'): {
                remote: WebSettings.SpamFilterValidationUrl
            }
        },
        messages: {
            field1.attr('name'): {
                remote: "Answer is incorrect."
            }
        },
    });
}

Is there any way I can achieve this?

  • 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-12T11:08:26+00:00Added an answer on May 12, 2026 at 11:08 am

    try construct validation options in steps so you can use [].
    See example below:

    function my_validate(field_name) {
       var opts = {rules:{},messages:{}};
       opts.rules[field_name] = {remote: WebSettings.SpamFilterValidationUrl};
       opts.messages[field_name] = {remote: "Answer is incorrect."};
       form.validate(opts);
    }
    

    UPDATE:
    Considering your updated question, here is the Init:

    function Init(form, field1)
       var opts = {rules:{},messages:{}};
       opts.rules[field1.attr('name')] = {remote: WebSettings.SpamFilterValidationUrl};
       opts.messages[field1.attr('name')] = {remote: "Answer is incorrect."};
       form.validate(opts);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my Javascript code 100% JSLint clean. I've got some JS
I was trying to clean up some accessability stuff in my code, and inadvertently
Trying to clean up some code. I have a button that has the following
I am trying to clean up some email addresses in sql server. I can
I am trying to clean up the javascript of a site. I am finding
I am trying to clean up some HTML values that are imported from other
I'm trying to test some code in different situations (for different result sets). I've
I am trying to use a textarea form entry which I have some javascript
I've got a Javascript mess that looks something like: Note: Not working code, just
I'm trying to create clean URLs on my website. Now I succeeded in configuring

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.