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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:48:10+00:00 2026-05-16T14:48:10+00:00

Im having a small problem, I’m trying to create an inline editing system with

  • 0

Im having a small problem, I’m trying to create an inline editing system with jquery. So when an user clicks on a table field the innerhtml will change into an input field with ofcourse the content of the table field. Onblur this input field is saved in a mysql db and the innerhtml change back to the new content. I want an user to edit the same text multiple times. If I use .live('click',function(){}); Every time the user clicks on the table field the input is added so i get an input replaced by an input with the value of the last input. Very annoying, I solved this using the .one function but now an user can only edit every table field once! Is there a way to disable an live event till the ajax call is completed?

The Jquery

$(document).ready(function(){
var id = 0;
$('table.editable td').one('click', function(event) {      

    var content = $(this).html();
    id = $(this).parent().find('.id').val();
    var class = $(this).attr('class');

    $(this).html('<input type="text" id="editablefield" name="'+class+'" value="'+content+'"/>');

    $(this).unbind(event);   
});

$('#editablefield').live('blur', function() {
    var value = $(this).val();
    var name = $(this).attr('name');
    $.ajax({
        type: "POST",
        url: "modules/Events/ajax/saveField.php",
        data: "id="+id+"&val="+value+"&type="+name,
        success: function(data) {
            var data = data;
            alert(data);
        },
        error: function(request, status, error) {
            alert(request.responseText);
        }
    });

    $(this).parent().html(value);
});

});

THE FRONTEND

<?php
$query = "SELECT * FROM mod_events";
$result = mysql_query($query) or die(mysql_error());



echo "<table class='editable'>";

echo "<tr>";
echo "<th></th>";
echo "<th>Event</th>";
echo "<th></th>";
echo "<th></th>";
echo "<th></th>";
echo "<th>Capacity</th>";
echo "</tr>";

while($row = mysql_fetch_assoc($result)) {

    echo ("<tr>");
    echo ("<td>");
    echo ("<input type='hidden' value='".$row['event_id']."' class='id'>");
    echo ("</td>");   
    echo ("<td colspan='4' class='event_name'>");
    echo ($row['event_name']);
    echo ("</td>");
    echo ("<td class='event_capacity'>");
    echo ($row['event_capacity']);
    echo ("</td>");

    echo ("</tr>");

}

echo "</table>";
?>

AND THE AJAX SCRIPT

<?php
require_once('../../../../config.php');
require_once("../../../../inc/dbconnect.php");

$id     = mysql_real_escape_string($_POST['id']);
$value  = mysql_real_escape_string($_POST['val']);
$field  = mysql_real_escape_string($_POST['type']);

$query =  "UPDATE mod_events SET ".$field." = '".$value."' WHERE event_id = ".$id;

echo mysql_query($query);


?>

Hope you guys can help me out!

  • 1 1 Answer
  • 1 View
  • 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-16T14:48:11+00:00Added an answer on May 16, 2026 at 2:48 pm

    You could check if there is already an input in this table cell like this:

    $('table.editable td').click(function(event) {      
        if ($('input',this).length == 0) { //check if there is already an input?
            var content = $(this).html();
            id = $(this).parent().find('.id').val();
            var class = $(this).attr('class');
    
            $(this).html('<input type="text" id="editablefield" name="'+class+'" value="'+content+'"/>');
    
            // $(this).unbind(event); // this shouldn't be needed anymore.
        }
    });
    

    to avoid the problem described by aularons comment:

    but that may cause this scenario: user clicks to edit, changes data to 555, a request is made but not completed yet, then the user changes the data to 333, now this request goes faster (first got routed somewhere slow or got it’s packet resent for some reason), now the user will see 333 in the field while on the server it’s 555, cuz the 555 request arrived after the 333. What I did was unbinding while the request is running, then binding again: jsfiddle.net/eDJqL – aularon

    You need to change the code like following.

    $('#editablefield').live('blur', function() {
        var value = $(this).val();
        var name = $(this).attr('name');
        var cell = $(this).closest('td');
        cell.data('request-running', true); // set data to remember request is running
        $.ajax({
            type: "POST",
            url: "modules/Events/ajax/saveField.php",
            data: "id="+id+"&val="+value+"&type="+name,
            success: function(data) {
                cell.data('request-running', false); // mark finished ajax call
                var data = data;
                alert(data);
            },
            error: function(request, status, error) {
                cell.data('request-running', false); // mark finished ajax call
                alert(request.responseText);
            }
        });
    
        $(this).parent().html(value);
    });
    

    and

    $('table.editable td').click(function(event) {      
        if ($('input',this).length == 0 || !$(this).data('request-running')) { //check if there is already an input? Or the old request is still runnig.
            var content = $(this).html();
            id = $(this).parent().find('.id').val();
            var class = $(this).attr('class');
    
            $(this).html('<input type="text" id="editablefield" name="'+class+'" value="'+content+'"/>');
    
            // $(this).unbind(event); // this shouldn't be needed anymore.
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

having a small problem. I'm trying to create a loop that will create an
Im having a small problem with my code. I have been trying to read
I'm having a small problem with AFNetworking. Im trying to have a simple call
I'm having a small problem trying to malloc this struct. Here is the code
I am having small problem. I am trying to replace words in sentence i.e.
Bit of a newb but just having a small problem using jquery cycle all
I'm having a small but annoying problem with trying to open a link in
i am having a small problem here. The table which dbml (LinqToSql designer) is
I am having a small problem in my code. I am trying to reverse
I am having a small problem with the jQuery cycle plugin and its timeout.

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.