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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:49:22+00:00 2026-05-22T12:49:22+00:00

I have a form where i’ve replaced the submit button with an input (with

  • 0

I have a form where i’ve replaced the submit button with an input (with type=button) with an onclick which calls an existing function:

<form accept-charset="UTF-8" action="/admin/message_campaigns" class="new_message_campaign" id="new_message_campaign" method="post">
  <!-- some fields -->
      <input onclick="confirmSubmit();" type="button" value="Send" />
</form>

In the confirmSubmit, i’d like to be able to dynamically get the form object (to submit it), instead of having to hardcode the form’s id, or pass it as part of the call to confirmSubmit(). I’d have thought that i could do this by first getting the dom element that was clicked on, ie something like this:

var form = $(this).parents("form");

where $(this) is the object that called the function, ie the input with the onclick. This doesn’t work though. I think it would work if i’d set it up with the .click(function(){ syntax. Can i get the element that called the function in a different way?

EDIT – got the answer from @claudio below, for clarity here’s the complete function and call:

<form accept-charset="UTF-8" action="/admin/message_campaigns" class="new_message_campaign" id="new_message_campaign" method="post">
  <!-- some fields -->
      <input onclick="confirmSubmit($(this));" type="button" value="Send" />
</form>

and the function itself. Note that ‘jConfirm’ is a method of the jquery-alerts plugin (http://abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/) but that’s not really relevant to this question – the key thing was just to get the form object, not what’s subsequently done with it:

function confirmSubmit(caller) {
  var form = caller.parents("form");
  jConfirm('Are you sure?', 'Please Confirm', function(result){
    if (result) {
      form.submit();
    } else {
      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-22T12:49:22+00:00Added an answer on May 22, 2026 at 12:49 pm

    You can pass the inline handler the this keyword, obtaining the element which fired the event.

    like,

    onclick="confirmSubmit(this);"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form for example: <input type=text /> <input type=file /> <input type=submit />
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have a form with many input fields. When I catch the submit form
I have form with one input for email and two submit buttons to subscribe
I have a form which contains 4 text fields when the button is clicked
I have a form submit button that has asp.net validators hooked up to it.
I have a form like this: one.php <form id='myFormId' name='myFormName'> <input type='text' name='myTextField'> <a
I have form area in my view. If I click button A , I
I have a form in C# that has a button that, when clicked, I
I have subclassed Form to include some extra functionality, which boils down to a

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.