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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:45:31+00:00 2026-06-08T11:45:31+00:00

How can I submit this form with ajax. Right now it creates a table

  • 0

How can I submit this form with ajax.

Right now it creates a table from mysql query. When you click the Edit button behind a row, Javascript makes all the cells to input=text.

Now when you click the Submit button at the end of the line I would like it to submit edited data to mysql via ajax.

I don’t understand where do I get the data that I need to POST with ajax.

<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.qtip-1.0.0.min.js"></script>
<script type="text/javascript">

$(document).ready(function(){
      $(".edit").click(function(){
          var tr = $(this).closest("tr");
          var submit = "<input type='submit' name='Submit' value='Submit' />";

          tr.find(".td").each(function(){
              var name = $(this).attr("title");
              var value = $(this).html();
              var input = "<input type='text' name='"+name+"' value='"+value+"' />";
              $(this).html(input);
          });

          tr.find(".button").html(submit);

      });
  });

// this is the id of the submit button
$(".button").click(function() {    

$.ajax({
       type: "POST",
       url: "index.php?page=update_mysql",
       data: $("#change").serialize(), // serializes the form's elements.
       success: function(data)
       {
           alert(data); // show response from the php script.
       }
     });

return false; // avoid to execute the actual submit of the form.
});
</script>

<form id="change" method="post" action="#">
    <table>

<?PHP
$sql="SELECT * FROM names";
$result = mysql_query($sql)or die(mysql_error());
  WHILE ($row = mysql_fetch_array($result, MYSQL_ASSOC))  {
        echo '<tr class="row">';
            echo '<td class="td" title="id">'.$row["id"].'</td>';
            echo '<td class="td" title="first_name">'.$row["first_name"].'</td>';
            echo '<td class="td" title="last_name">'.$row["last_name"].'</td>';
            echo '<td class="button" title="button"><button class="edit">Edit</button></td>';
        echo '</tr>';
  }
?>

    </table>
</form>

And update_mysql.php looks like this:

<?php
include 'firewall.php';
if ($_POST['Submit'] == "Submit") {
$id = $_POST['id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$sql_edit = "UPDATE names SET first_name = '$first_name', last_name = '$last_name' WHERE id = '$id'";
$result_edit = mysql_query($sql_edit) or die(mysql_error());

}

?>
  • 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-08T11:45:33+00:00Added an answer on June 8, 2026 at 11:45 am

    Try this.

    $(document).ready(function(){
      $(".edit").click(function(){
        var tr = $(this).closest("tr");
    
        tr.find(".td").each(function(){
          var name = $(this).attr("title");
          var value = $(this).html();
          var input = "<input type='text' name='"+name+"' value='"+value+"' />";
          $(this).html(input);
        });
    
        var submit = "<input type='button' name='Submit' value='Submit' />";
        tr.find(".button").html(submit);
    
      });
    });
    
    $(".button input[type=button]").live('click', function() {
      var data = $('form#change').serialize();
      // post data using ajax                                                                                                                                                                         
      $.ajax({
        type: "POST",
        url: "index.php?page=update_mysql",
        data: data,
        success: function(data) {
          alert(data); // show response from the php script.                                                                                                                                          
        }
      });
    });
    

    NOTE: I have changed the “type” attribute of submit button to “type=’button'”. That will not fire default submit of browser. The same button is bound to collect form data and submit using ajax.

    Happy Coding.

    EDIT:

    It takes you to “index.php?page=my_page#” coz form is submitted whey you click the <input type="submit">. Haven’t you changed it to <input type="button"> yet? You don’t need a submit button when its not there to submit the form. There are other non-submit button to bind javascript handlers to.

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

Sidebar

Related Questions

Right now, users click a button with JQuery. It dynamically adds a new form
I am newbie to jQuery, can someone explain what this code does: $(#currency form).submit(function(e)
This is my program .when i submit the print button i can print the
I know that a submit button in HTML can submit a form which opens
How can I submit jQuery form object (not ajax)? I try form.submit() and it
I am wondering how would I do this with like jQuery ajax. Right now
I have this code: $('#my_form .submit').click( -> $.ajax( -> type: post, url: ????, data:
Right now I can call a method using ajax (:remote=> 'true') at awisprotect_path by
I would like to have a form that can submit to two different action
I want to redirect my controller methods, so that I can submit a form

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.