I want to make that when clicking on a table cell, a temporary input tag is added to which we enter a new value, and when the focus is removed, ajax would be executed. And in case the request was successful, change the contents of the cell in the browser. The transmitted data in the ajax id of the tr tag, the id of the td tag and the value entered in the input
html:
<tr id='1'><td id='ip' class='edit'>1231412411</td></tr> ajax:
$('.edit').click(function(e) { e.preventDefault(); $(this).html("<input type='text' value='"+$(this).text()+"'/>"); }).click(function(e) { e.preventDefault(); return false; }).blur(function(e) { var send_id = $(this).closest('tr'); var tag = $(this).attr('id'); var info = $(this).text(); function funcSuccess(data) { if(data=='ok') { tag.text($(this).val()); } } e.preventDefault(); $.ajax ({ url: "edit.php", type: "POST", data: ({id: send_id, type: tag, value: info}), dataType: "html", success: funcSuccess }); }); and PHP itself:
<?php include('connect_db.php'); if(isset($_POST['id'])&&isset($_POST['type'])&&isset($_POST['value'])){ $id = $_POST['id']; $type = $_POST['type']; $value = $_POST['value']; if(mysql_query ("UPDATE dashboard SET '$type' = '$value' WHERE id = '$id'")) echo 'ok'; } else { echo 'error'; } } else { echo 'error'; } ?>
$('.edit').click(...).click(...)??? - Igor