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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:09:18+00:00 2026-05-16T01:09:18+00:00

For example, I have a HTML form with several input buttons, <form action=/index.php method=post>

  • 0

For example, I have a HTML form with several input buttons,

 <form action="/index.php" method="post">
 <input type="hidden" name="hf" />
 <input type="submit" id="apply_action" name="action" value="Apply">
 <input type="submit" id="cancel_action" name="action" value="Cancel">

it’s the current framework of a large web project. Once Submit button ‘Apply’ is clicked, it will map to a particular PHP function on the web server, and then return certain HTML code back; of course, once ‘Cancel’ is clicked, it will map to another PHP function.

Now, I would like to add some stuff before the original submit action when the ‘Apply’ is clicked. For example: I would like to add an javascript alert (“hello”) before the original submit action is sent to the server? I dont know how to achieve this with Jquery? First of all, there are two submit actions for this form, value=’Apply’ or ‘Cancel’, I need to differentiate the action;
Second, after alert(‘hello’), I still need the original form action=’index.php’ to be executed.
Is there a jquery function for this purpose? Thanks!

  • 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-16T01:09:19+00:00Added an answer on May 16, 2026 at 1:09 am

    It sounds like you wish to bind a function to the form’s submit event. See http://api.jquery.com/submit/

    To fit your request, this should work:

    $('form').submit(function(){
      alert('hello');
      return true;
      });
    

    Addendum:

    Okay, since you have two submit buttons, you’ll need to use the click event.

    $(document).ready(function(){
      $('input').click(function(ev){
       alert(ev.target.id);//this is how you will differentiate between the two buttons.
          //or, you could bind a separate click event to each one
       if(ev.target.id=="cancel_action"){ /* etc.. */ }
       else{ /* etc.. */ }
       });
     });
    

    With either method, the form will be submitted on click. As noted by Francisco Soto, returning false will prevent the submission from either method. Returning true (or not specifying a return value) will continue with the form submission.

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

Sidebar

Related Questions

I have an html form like this: <form id=boxy action=layout.html method=get accept-charset=utf-8> <input type=text
I have a html form that his action is for exmaple.com/mail.php?name=dan for example. How
Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
I have a slider I made: http://dranz1r.com/index.html When you slide right for example, there
I have an HTML / PHP Form. on the form the date and time
I have successfully setup an HTML form in PHP File #1, and it is
So for example I have a simple HTML form: <h3> <a href=#>Login</a> </h3> <div
I have HTML form with lots of select and input fields, using it a
I have a form UI whereby several sections require duplicate HTML select list to
Hi just looking for some direction, I have a HTML form which has several

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.