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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:46:19+00:00 2026-05-28T00:46:19+00:00

I’m trying to make an editable table for a tournament using jQuery and ajax.

  • 0

I’m trying to make an editable table for a tournament using jQuery and ajax.

The present table structure is as follows:

<table>
<tr id="result-243">
<td class="name">Somebody</td>
<td class="score_1">9.0</td>
<td class="score_2">7.0</td>
<td class="score_3">7.8</td>
<td class="score_4">9.9</td>
<td class="score_5">7.9</td>
<td class="edit-243"><div id="edit-243" class="edit">Edit</div></td>
</tr>
</table>

What I want is to insert a form when the ‘Edit’ link is clicked. This form would be populated with values from the current entry. I can make this work as follows:

$('.edit').click(function() {
        result_id = $(this).attr('id').match(/[0-9]+/);
        sel = '#result-' + result_id;
        $.get(
            myScript.ajax_url, 
            {
                action:'getResults',
                id:result_id,
                nonce: myScript.nonce
            },
            function( response ) 
            {
                form = "<form id='save-" + result_id"' class='post-me'>";
                for(value in response) {
                    form += "<input type='text' name = '" + value + "' value = '" + response[value] + "' />";
                }
                form += "<input type='submit' id='save-this' name='save' value='Save' /></form>";
                $(sel).html(form);
            }
            );
    });;

I would obviously expect to be able to bind the form to a $.post() request, and that should post the data. However, the problem I seem to be running into is as follows:

If I want to restore the previous table elements (as above) with new values, I can’t click ‘Edit’ again. I think it’s because jQuery will bind events to DOM elements inserted on the fly, but only once. I can’t remove the elements without losing the event binding.

Any ideas for what’s wrong with my design approach?

  • 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-28T00:46:20+00:00Added an answer on May 28, 2026 at 12:46 am

    Can you use ContentEditable instead (html5)? Then you can just wrap up the edited table and send the new values in once they are changed.

    http://jsfiddle.net/5Ut8x/

    <table contenteditable>
    

    Testing for ContentEditable support.

    Thinking about your question some more and your existing framework – I think you can work around the event binding problem by either using on or not destroying old values until the form is actually submitted. Just hide the table row and replace with a form.

    Then if the form is actually submitted destroy the old row. If user cancels out of submission then destroy the form and reshow the old row. Here is an example fiddle.

    http://jsfiddle.net/5Ut8x/1/

    $('.edit').click( function() {
        var $form = $('<tr><td><form><input type="text" /><button class="cancel">cancel</button><button class="submit">Submit</button></form></td></tr>');
        $(this).closest('tr').hide().after($form);
        return false;
    });
    
    //on cancel click show old row and remove the form row 
    $('table').on('click', '.cancel', function() {
        $(this).closest('tr').prev('tr').show().next('tr').remove();
    });
    
    //on submit click remove old row
    $('table').on('click', '.submit', function() {
        $(this).closest('tr').prev('tr').remove();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.