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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:04:41+00:00 2026-06-02T00:04:41+00:00

Background: I have a jQuery validation script, which is used on almost all my

  • 0

Background: I have a jQuery validation script, which is used on almost all my webpages, allowing for client-side validation (I also do server-side validation). The javascript is the same for all my pages, except for the specific ‘rules’ for each form.

The rules for each page are inserted into a php variable $jquery_validation from my controllers prior to rendering the HTML page. This means I can dynamically generate each html page & form, with the appropriate client-side validation rules.

Below is my javascript code that is currently loaded on ALL my html pages:

$(document).ready(function(){
      $('#signupform').validate({
           wrapper: 'span class="error"',
           meta: 'validate', 
           highlight: function(element, errorClass, validClass) {
               if (element.type === 'radio') {
                      this.findByName(element.name).addClass(errorClass).removeClass(validClass);
              } else {
                      $(element).addClass(errorClass).removeClass(validClass);
               }

              var error = $(element).parent().find('span.error');       
                error.show();     
            },

             unhighlight: function(element, errorClass, validClass) {
              if (element.type === 'radio') {
                this.findByName(element.name).removeClass(errorClass).addClass(validClass);
              } else {
                $(element).removeClass(errorClass).addClass(validClass);
              }

              $(element).parent().find('span.error').hide(0, function() {
                $(element).parent().find('span.valid').fadeIn(200);
              });
            },
            <?=$jquery_validation?>);});

</script>

the $jquery_validation variable at the end contains the “rules” for each page, which are obviously different depending on the form. An example of the output it gives is:

 "rules":{"username":{"required":true,"remote":{"url":"http:\/\/localhost\/mytest\/public_html\/welcome\/remote","type":"post"}},"onkeyup":false});});

The function is working now, and all is good.

Question: Is there a way to have my validation javascript function in my .js file (so it can be compressed etc) – and still dynamically load the “rules” section of the validation for each page?

I can change the ‘output’ & syntax of the $jquery_validation if required – but the point is I need to be able to output the rules for each page dynamically

  • 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-02T00:04:43+00:00Added an answer on June 2, 2026 at 12:04 am

    Yes, you can create an object and save it off to a variable and save off the details in the constructor (can’t remember what it’s called in JS).

    Here is an example I use in one of my scripts.

    var rmlsSearch = function(searchEndpoint) {
    
      this.fname = '';
      this.lname = '';
      this.searchEndpoint = searchEndpoint;
      this.resultTemplate = $('#rmls-search-result-template').html();
    
      //Preform inital search
      this.searchAgent();
    
      //Bind search function to search button
      $('#rmls-search-button').one('click', $.proxy(this.searchAgent, this));
    
    };
    

    With that defined you can then instantiate it wherever you want and pass in whatever details you need.

    var rmlsHandle = rmlsSearch("some endpoint I'm planning on using");
    

    The search Agent function, prototyped into the object:

    rmlsSearch.prototype.searchAgent = function(){
    
      //Get the agent details from the form on the page
      this.getAgentDetails();
    
      //... Whatever else you'd need to do in the function
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client that is wanting to have jquery.colorbox and wants the background
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
Background: I have a jQuery Datatable with 53x columns. The first column is the
I have this jQuery call for a dropdown. On click, the background image of
I'm using the jquery tabs plugin and want to have the background a light
Can I have text in the background of a jQuery UI progress bar? You
Background I have been asked by a client to create a picture of the
I have a jquery dialog box that is used to edit and update a
I have a form with two input textboxes, and I have included jQuery validation
I have this jquery issue that seems to only break when using background image

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.