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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:28:55+00:00 2026-06-10T08:28:55+00:00

I wrote a plugin to validate forms across the network where i work. The

  • 0

I wrote a plugin to validate forms across the network where i work. The problem here is that some of our pages have multiple forms and the global variables get overwritten. I’ll try to give an example as best i can. The code itself would be too long to paste.

I know this code is horribly wrong but i’m trying to gauge the best way to achieve using multiple instances of this code without making things too complicated.

jquery plugin:

(function($){

    methods = { 
        'method1': function(){
            alert('form: ' + globals.form_name ); 
        }
    }

    $.fn.validationplugin = function() {
        globals.form_id = $(this).attr('id');
    }(jQuery);

    var globals = {}


}(jQuery);

html calls:

<form id="form1"></form>
<form id="form2"></form>

<script type="text/javascript">
    $('#form1').validationplugin();
    $('#form2').validationplugin();
</script>
  • 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-10T08:28:56+00:00Added an answer on June 10, 2026 at 8:28 am

    Use an array for the form identities:

    var globals = {
      form_id: []
    };
    

    The plugin can be called with a single element or several elements, so you have to get the identities for each element. Also return this from the function so that the plugin can be chained. Also, you don’t want (jQuery) at the end, as that will call the function and assign the return value as the plugin:

    $.fn.validationplugin = function() {
      return this.each(function(i, el){
        globals.form_id.push($(el).attr('id'));
      });
    };
    

    Now it also works when there is more than one element in the call:

    $('#form1,#form2').validationplugin();
    

    Consider if you can use the reference to the elements instead of their identity, then it would work for a form without an identity also.

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

Sidebar

Related Questions

I wrote a Resharper plugin that seems to only work when users have the
I'm using the jQuery Validation plugin on my forms. I have some groups of
I am using jquery.validate.js plugin for a dialog validation. My problem is that I
I want to write a plugin to validate forms. I have made detailed research
I have Dynamics CRM 4.0 installed and wrote a plugin, registered it, and setup
I wrote a simple plugin which sets some css code using wp_options. It all
I wrote a jQuery plugin that binds to 8 elements on a page, and
I wrote a custom wordpress plugin that is shown in the left menu bar
I found the jquery validation plugin ( http://plugins.jquery.com/project/validate ) and thought that this would
I wrote a beginner jQuery plugin which validate a form. this jQuery Plugin show

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.