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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:24:13+00:00 2026-06-05T06:24:13+00:00

I have a basic AJAX form submission function in the head of my page

  • 0

I have a basic AJAX form submission function in the head of my page (stolen from a tutorial because I can’t write this stuff from scratch). In the body of my page I have a bunch of forms with hidden inputs that have values corresponding to user id’s that are in my database.

The idea is that when you submit a form, the hidden value is POST’d to my PHP page where it deletes the user with that id from my MySQL database. It’s all pretty straight forward and there’s probably a much more efficient way to do it but this is the only way I could think of.

Anyway the problem is my AJAX function only works with the first form in my page. When I submit the form, the user is deleted from my database, the page refreshes and that particular form disappears. But if you click any form beneath the top one, nothing happens. Here’s my jQuery function:

<script type="text/javascript">


$(document).ready(function(){
    $("#myform").validate({
        debug: false,
        rules: {
            group: {required: true}, 
        },
        messages: {
            group: {required: " Field required.", loginRegex: " Invalid character."},
        },
        submitHandler: function(form) {
            $.post('process_delete_participant.php', $("#myform").serialize(), function(data) {
                $('#results').html(data);
            });
        }
    });
});


</script>

And here’s what’s in the body of my page:

<?php

$query = mysql_query('SELECT * FROM `Participant`');
    if (!$query)
{ 
    die('Query failure: '.mysql_error()); 
}

while($rows = mysql_fetch_array($query))
{

$fname = $rows['firstName'];
$sname = $rows['secondName'];
$id = $rows['idParticipant'];

echo "<form name='myform$id' id='myform$id' action='' method='POST'> ";
echo "<input type='hidden' name='idParticipant' id='$id' value='$id' />";
echo "$fname ";
echo "$sname ";
echo "<input type='submit' name='submit$id' id='submit$id' value='Delete' /> ";
echo "</form>";
echo "<br><br>";

}

?>

So an example of one of the forms could look something like this:

<form name='myform61' id='myform61' action='' method='POST'> 
<input type='hidden' name='idParticipant' id='61' value='61' />John Smith
<input type='submit' name='submit61' id='submit61' value='Delete' /> 
</form>

I can think of a couple of reasons why the function only works with the topmost form but I have no idea what to edit in the syntax of my function to solve the issue. Anyone know?

  • 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-05T06:24:15+00:00Added an answer on June 5, 2026 at 6:24 am

    The selector in the example is by ID explicitly. You could try $(“[id^=myform]”) as this matches the beginning of an id.

    Also, replace the second call to “$(“#myform”)” with $(this) to ensure the correct context.

    edited (added):

    $("[id^=myform]").validate({
            debug: false,
            rules: {
                group: {required: true}, 
            },
            messages: {
                group: {required: " Field required.", loginRegex: " Invalid character."},
            },
            submitHandler: function(form) {
                $.post('process_delete_participant.php', $(this).serialize(), function(data) {
                    $('#results').html(data);
                });
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built a basic form with ajax validation and page redirection with PHP and
I have a basic page, with a div containing text, and a form to
I have a basic ajax form on my site utilizing the Js helper, it
I have a basic login form, which uses ajax to login users. If the
I have a very basic email submission form in my ASP.NET MVC 3 app.
I have an AJAX call which dynamically generates a HTML form. This form contains
In this basic jQuery, AJAX, PHP form I want to display errors next to
I'm developing this app which as a very basic Ajax form and I'm currently
I have a basic class that derived subclasses inherit from, it carries the basic
I have a basic question, in the Django template language how can you tell

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.