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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:46:15+00:00 2026-06-08T00:46:15+00:00

I am adding ajax to this little list web app I made. I have

  • 0

I am adding ajax to this little list web app I made.

I have buttons being output by a php script for each item of a list. I want to call ajax to delete an item with php and mysql when the delete button is clicked for one of the items.

Below is the delete button for item 62. It has a hidden field which contains the id of the list item in the database. When the button is clicked I want a jquery click event to be called which should send off an ajax request to delete the item with that id from the database.

<form class="actions" action="index.php" method="POST">
<input type="hidden" name="idDel" id="62" value="62">
<input type="submit" class="button delete" value="X">
</form>

The jquery I have thought of so far is below. When a button with the class .delete is clicked (any of the delete buttons) it needs to somehow get the id value from the hidden field.

('.delete').click(function(){
              //add click logic here

              var id = $("input.delete").val();

    return false;

    $.ajax({
      type: "POST",
      url: "delete.php",
      data: id,
      success: function() {

Now, I have looked at two similar questions and tried their solutions but I could not figure out the code from them.

  1. JQuery – which form was submitted?
  2. How can I get the button that caused the submit from the form submit event?

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-06-08T00:46:18+00:00Added an answer on June 8, 2026 at 12:46 am

    Use $(this) to reference the button that was clicked, then use .prev() to get the element before the button, which is the input you want in this case:

    $('.delete').click(function() {
        // Add click logic here
    
        var id = $(this).prev('input').val();
    
        return false;
    
        $.ajax({
            type: "POST",
            url: "delete.php",
            data: id,
            success: function() {
    
            });
        });
    });
    

    You could also store the ID in a data- attribute of the button itself, which would mean less HTML (but you would lose the non-JS POST-ability of the form):

    HTML:

    <form class="actions" action="index.php" method="POST">
       <input type="submit" class="button delete" value="X" data-id="62">
    </form>
    

    jQuery:

    $('.delete').click(function() {
        // Add click logic here
    
        var id = $(this).data('id');
    
        return false;
    
        $.ajax({
            type: "POST",
            url: "delete.php",
            data: id,
            success: function() {
    
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first attempt at adding ajax to a WordPress plugin. I have
I'm having a little problem with this setup here I have a list of
I Have a working PHP Based Pagination onto which i am adding ajax to
I am having trouble adding ajax functionality to existing asp.net 4 website. I have
I have what I thought was a relatively easy Ajax/animation that I'm adding to
I want to slow down my app by adding latency for ajax requests. I
I've got a nice MVC app running now, and I'm adding some AJax functionality.
I have a page called example1.php . This page calls another page with some
I have this polling script to check if a text file is created on
So, I have a page that is made up of 4 different AJAX containers

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.