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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:07:47+00:00 2026-05-24T12:07:47+00:00

So I have multiple forms on a page. Each form is identical except for

  • 0

So I have multiple forms on a page. Each form is identical except for the data they may contain. I am listening for changes to a specific elements that should modify other elements within its same form, but I am having trouble figuring out how to scope those actions within its own form. Here’s what I’ve got so far:

var ContactSponsor = new function(){

    this.init = function(){
        $('#SponsorStatus_ID').change(SponsorStatusChanged);
    };

    var SponsorStatusChanged = function(){

        var $form = $(this).closest('form');
        var selectedValue = $(this).find('option:selected').text();

        if (selectedValue == 'Executed Contract') {
            markFieldRequired('#NumVAPs', $form);
            markFieldRequired('#SponsorWebsiteLevel_ID', $form);
            autoFillFieldWithCurrentDate('#ContractDate', $form);
        } else {
            markFieldNotRequired('#NumVAPs', $form);
            markFieldNotRequired('#SponsorWebsiteLevel_ID', $form);
        }
    };

    var markFieldRequired = function(fieldID, $form){
        $(fieldID, $form).siblings('label').addClass('required');
    };

    var markFieldNotRequired = function(fieldID, $form){
        $(fieldID, $form).siblings('label').removeClass('required');
    };

    var autoFillFieldWithCurrentDate = function(fieldID, $form){
        if ($(fieldID, $form).val() == '' || $(fieldID, $form).val() == '0000-00-00') {
            $(fieldID, $form).val(getCurrentDate());
        }
    };
};

Also, I’m passing the form to each of the methods. Not sure if there is a way I can do this without passing it in every time.

  • 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-24T12:07:48+00:00Added an answer on May 24, 2026 at 12:07 pm

    It looks like you’re using duplicate IDs. That is probably going to cause problems. Rather than having each FORM include an input with id=NumVAPs, remove the ID and then target the field by name instead e.g. $form.find('[name=NumVAPs]').

    And hey, while we’re at it, you might want to combine your markFieldRequired and markFieldNotRequired functions into a single setFieldRequired that accepts a boolean indicating whether the field should be required or not.

    Also, if marking a field as required is purely cosmetic, you may want to consider handling that with some CSS instead. E.g.:

    var SponsorStatusChanged = function(){
        var $this = $(this);
    
        if($this.val() == 'Executed Contract') {
            $this.closest('form').addClass('executed');
        }
    }
    

    Then, add this CSS:

    form.executed label.required-for-executed {
        /* whatever rules are conferred by .required */
    }
    

    OR add that selector to the .required block. Also, you’ll have to add the class required-for-executed to each of the appropriate labels in the markup (i.e. don’t do it with javascript).

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

Sidebar

Related Questions

I have multiple forms on a page, for each of them I want the
I have a page that creates multiple forms for each object that I had
I have a form on an HTML page with multiple submit buttons that perform
I have a form element that contains multiple lines of inputs. Think of each
I have a form made up of multiple, optional subparts - each of which
I have a form that will multiple Panel controls stacked on top of each
I have a table with multiple rows. Each row is a form. I want
I have a page that contains several forms that are identical throughout a page.
Is it an acceptable practice to have multiple HTML forms on a page with
I have multiple forms on a page which pass an id to the controller

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.