Note that there are some explanatory texts on larger screens.

plurals
  1. POReset one function after ajax is completed
    primarykey
    data
    text
    <p>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 <code>.live('click',function(){});</code> 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 <code>.one</code> 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?</p> <p>The Jquery</p> <pre><code>$(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('&lt;input type="text" id="editablefield" name="'+class+'" value="'+content+'"/&gt;'); $(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+"&amp;val="+value+"&amp;type="+name, success: function(data) { var data = data; alert(data); }, error: function(request, status, error) { alert(request.responseText); } }); $(this).parent().html(value); }); }); </code></pre> <p>THE FRONTEND</p> <pre><code>&lt;?php $query = "SELECT * FROM mod_events"; $result = mysql_query($query) or die(mysql_error()); echo "&lt;table class='editable'&gt;"; echo "&lt;tr&gt;"; echo "&lt;th&gt;&lt;/th&gt;"; echo "&lt;th&gt;Event&lt;/th&gt;"; echo "&lt;th&gt;&lt;/th&gt;"; echo "&lt;th&gt;&lt;/th&gt;"; echo "&lt;th&gt;&lt;/th&gt;"; echo "&lt;th&gt;Capacity&lt;/th&gt;"; echo "&lt;/tr&gt;"; while($row = mysql_fetch_assoc($result)) { echo ("&lt;tr&gt;"); echo ("&lt;td&gt;"); echo ("&lt;input type='hidden' value='".$row['event_id']."' class='id'&gt;"); echo ("&lt;/td&gt;"); echo ("&lt;td colspan='4' class='event_name'&gt;"); echo ($row['event_name']); echo ("&lt;/td&gt;"); echo ("&lt;td class='event_capacity'&gt;"); echo ($row['event_capacity']); echo ("&lt;/td&gt;"); echo ("&lt;/tr&gt;"); } echo "&lt;/table&gt;"; ?&gt; </code></pre> <p>AND THE AJAX SCRIPT</p> <pre><code>&lt;?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); ?&gt; </code></pre> <p>Hope you guys can help me out!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload