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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:58:54+00:00 2026-05-26T06:58:54+00:00

I am writing my own form validation plugin. I am making to work with

  • 0

I am writing my own form validation plugin. I am making to work with multiple forms on a page. when the form is submitted it is validated. The problem I am having is that in the plugin I can loo through the elements of the form but in the .submit I can only access the last form of the set sent to j!uery. my html is 2 forms. on has an input with a name of num and the other has one named alpha. they both have their own submit button. below is the main section of the jQuery plugin. for the plugin in am simply sending it form. o.attr is stores the name of the attribute with the validation rules.

    var options =  $.extend(defaults, options);
    return this.each(function() 
    {
    form=this;
    var o = options;
    //this gets me both inputs on page load
    $('['+o.attr+']', form).each(function()
    {
        var val=$(this).val()
        alert($(this).attr('name'))
    })
    //on submit It will alert the last forms input regardless of what form i submited
    $(this).submit(function()
    {
        var o = options;
        $('['+o.attr+']', form).each(function()
        {
            var val=$(this).val()
            alert($(this).attr('name'))
        })
        return false;
    })
    });
  • 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-26T06:58:54+00:00Added an answer on May 26, 2026 at 6:58 am
    form=this;
    

    You forgot to declare your form var, so it’s an accidental global variable and not captured in a closure as you expected.

    Consequently by the time the submit function is called form will always hold the last value of this regardless of which form was submitted.

    (Use a lint tool on your code, or an ECMAScript Fith Edition Strict Mode-supporting browser, to detect accidental globals.)

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

Sidebar

Related Questions

I am writing a web application that lets a user create their own forms
I am writing my own control that will contain a panel with text, images
I'm working on a jQuery function that forwards form data to page without interfering
I'm writing an application that lets the end use design a Form just the
I am writing a basic jQuery form validation script and I have something like
I am writing a Firefox extension that needs to write and submit a form
I am writing my own Joomla component (MVC), its based heavily on the newsflash
I just finished writing my own collecion class, and i'd really like to make
Basically I'm writing my own version of a 'RoleProvider' and 'AuthorizeAttribute'. I've got an
I am writing my own blog (every one should, it's good experience). I have

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.