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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:37:01+00:00 2026-06-17T22:37:01+00:00

Now I know this sounds elementary, but I honestly can’t dial this in. I

  • 0

Now I know this sounds elementary, but I honestly can’t dial this in. I have two forms on a single page. I wrote some form validating functions that are triggered as such:

$("form").submit(function(event) {
    event.preventDefault();
    checkRequired();
    checkLengths();
    checkFormats();
    checkErrors();
});

This is awesome, but inside the functions, I cannot use $(this) to identify the <form> from which the submit button was clicked.

Let’s say I wrote alert($(this).attr('id')); in the checkRequired() function. It alerts “Object, object“.

If I place the same code inside the $("form").submit() function, it returns my form’s id.

The selectors inside the functions are things like $("input[type='text']") and similar, but the functions run on all the inputs, not just the ones in the form that was submitted.

Sample function() used:

function checkFormats() {

    alert("Checking Formats...");

    $(".email").each(function(){

        alert("Checking Formats: Email...");

        var emailField = $(this).children("input[type='text']");
        var strEmail = emailField.val();

        if( strEmail.indexOf( "@" ) == -1 ) {
            alert("What the hell?");
        }

    });

}

I’m sure I’ll feel dumb when I hear the solution, but hey, I’m overly-tired lol… Thanks in advance!

Thinking maybe $("form",this) may get me somewhere?

  • 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-17T22:37:02+00:00Added an answer on June 17, 2026 at 10:37 pm

    Can you not pass the form to the methods?

    $("form").submit(function(event) {
        event.preventDefault();
        checkRequired(this);
        checkLengths(this);
        checkFormats(this);
        checkErrors(this);
    });
    

    Then you have the right context.
    You can now select any additional elements within the context of the specified form, similar to this::

    function checkFormats(theForm) {
        $form = $(theForm);
    
        alert("Checking Formats...");
        
        // Get emails from within the context of the current form.
        $(".email", $form).each(function(){
    
            alert("Checking Formats: Email...");
    
            var emailField = $(this).children("input[type='text']");
            var strEmail = emailField.val();
    
            if( strEmail.indexOf( "@" ) == -1 ) {
                alert("What the hell?");
            }
    
        });
    }
    

    Alternative – Use JavaScript .apply

    (As mentioned by Mike Robinson in the comments)


    $("form").submit(function(event) {
        event.preventDefault();
        checkRequired.apply(this);
        checkLengths.apply(this);
        checkFormats.apply(this);
        checkErrors.apply(this);
    });
    

    Then this within the function becomes the form. You can now use it like this:

    function checkFormats(theForm) {
        $form = $(this);
    
        alert("Checking Formats...");
        
        // Get emails from within the context of the current form.
        $(".email", $form).each(function(){
    
            alert("Checking Formats: Email...");
    
            var emailField = $(this).children("input[type='text']");
            var strEmail = emailField.val();
    
            if( strEmail.indexOf( "@" ) == -1 ) {
                alert("What the hell?");
            }
    
        });
    }
    

    DEMO – Using .apply


    Demo uses a simple HTML From:

    <form>
        <button type="submit">submit</button>
    </form>
    

    With this script:

    $("form").submit(function (event) {
        event.preventDefault();
        checkRequired.apply(this);
    });
    
    function checkRequired() {
        alert("This is of type: " + this.nodeName);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this sounds strange, but on my development box I can't go back
I know this sounds a little ridiculous, but I'm just honestly wondering how I
Now this may seem like a silly question, but I need to know how
Now i know to use the method of float.Parse but have bumped into a
I know this sounds pretty trivial, but I'm new to jQuery... I use this
I know this sounds strange, mixing CDI (Weld) and Spring for the controller. But
I know this sounds backwards but I would like to be able to determine
I know this sounds extremely newbieish, but even after going through some of the
This sounds like a trivia question but I really need to know. If you
I don't know if this is possible but it sounds like something that should

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.