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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:42:10+00:00 2026-05-16T14:42:10+00:00

I use the $.post function to submit an ajax request as such: $(‘.typeAform’).submit(function(){ $.post(‘/home’,

  • 0

I use the $.post function to submit an ajax request as such:

$('.typeAform').submit(function(){
    $.post('/home', { somevar : 'somevalue' }, function(){
         //do something with the original form
    });
    return false;
});

I’d like to identify my form after submission from the $.post callback so I can do something with it (i.e. change its background color, delete it, etc…).
Normally, I’d be able to call the form by its unique id that I know ahead of time, but here I don’t have it – I am using a class for the form, not a single id.

Is there a way I can identify the form I just submitted without using a global variable (i.e. pass it to the callback somehow).

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-16T14:42:10+00:00Added an answer on May 16, 2026 at 2:42 pm

    EDIT:

    Because the target of the submit event should always be the form itself, you could also use the target property of the event object, as in: e.target

    $('.typeAform').submit(function( e ){
        $.post('http://apple.com', { somevar : 'somevalue' }, function(){
             // e.target references the form that was submitted.
             alert(e.target)
        });
        return false;
    });​
    

    If this gives you trouble, then there are other ways to avoid creating a variable if you don’t want that.


    Get the ID from the DOM element in the .submit():

    var id = this.id;
    

    So it would be:

    $('.typeAform').submit(function(){
        var id = this.id;
        $.post('/home', { somevar : 'somevalue' }, function(){
             //do something with the original form
             // Use the "id" here
        });
        return false;
    });
    

    Or if you want the form itself, just reference this.

    $('.typeAform').submit(function(){
        var theForm = this;
        $.post('/home', { somevar : 'somevalue' }, function(){
             //do something with the original form
             // Use the "theForm" here
             alert( theForm.id );
             $(theForm).someJQueryMethod()
        });
        return false;
    });
    

    Note that once you’re inside the $.post callback, this no longer references the <form>. That’s why we referenced it in a variable.

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

Sidebar

Related Questions

I am trying to use the jQuery $.post method to submit an ajax request
When i use jquery's $.post ajax function, page freezes for 2-3 seconds and then
I'm attempting to use jQuery's $.ajax() function to post form variables to an MVC
I'm trying to use the following code to log users in: $(form).submit(function(event) { $.ajax({
I use jquery post function to go to server and bring the link to
quick question, is it secure to use the jQuery.post function in jQuery to pass
I'm trying to use $.post within a function, get the results, then return the
I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
How can I enable or trigger the submit event after ajax post? For instance
I have 2 functions, submit() with $.ajax and click() with $.post . In the

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.