Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing clicked cell instead of all cells using JQuery and Ajax
    primarykey
    data
    text
    <p>I am trying to edit a specific cell once it's clicked. When I click a cell currently it turns all the <code>td</code> into textboxes. I would like only the clicked cell do that. How can I access just the clicked cell? Here is my current code: (ignore the <code>.change</code> function for now; I haven't fixed it yet.</p> <pre><code> $(document).ready(function() { $(".edit_td").click(function() { $(this).children(".text").hide(); $(this).children(".editbox").show(); }).change(function() { var id=$(this).parent(); var field=$("#input_"+ id).val(); var text=$("#span_" + id).val(); var dataString = 'id='+ id +'&amp;field='+ field +'&amp;text='+ text; //$("#first_"+ID).html('&lt;img src="load.gif" /&gt;'); // Loading image if(input != text) { $.ajax({ type: "POST", url: "table_edit_ajax.php", data: dataString, cache: false, success: function(html) { $("#first_"+ID).html(first); $("#last_"+ID).html(last); } }); } else { alert('Enter something.'); } }); // Edit input box click action $(".editbox").mouseup(function() { return false }); // Outside click action $(document).mouseup(function() { $(".editbox").hide(); $(".text").show(); }); }); </code></pre> <p>This is my PHP code:</p> <pre><code> public function displayTable($table) { //connect to DB $con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); echo "&lt;table id='table' border='1'&gt;"; //start an HTML table $dbtable = $table; $fields =array(); $result = mysqli_query($con, "SHOW COLUMNS FROM ".$dbtable); //fill fields array with fields from table in database while ($x = mysqli_fetch_assoc($result)) { $fields[] = $x['Field']; } $fieldsnum = count($fields); //number of fields in array //create table header from dbtable fields foreach ($fields as $f) { echo "&lt;th&gt;".$f."&lt;/th&gt;"; } //create table rows from dbtable rows $result = mysqli_query($con, "SELECT * FROM ".$dbtable); while ($row = mysqli_fetch_array($result)) { $rowid = $row[$fields[0]]; echo "&lt;tr class='edit_tr' id='".$rowid."'&gt;"; foreach ($fields as $f) { echo "&lt;td class='edit_td'&gt;&lt;span id='span_".$rowid."' class='text'&gt;".$row[$f]."&lt;/span&gt; &lt;input type='text' value='".$row[$f]."' class='editbox' id='input_".$rowid."'/&gt; &lt;/td&gt;"; } $rowid++; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; //close the HTML table //close connection mysqli_close($con); } </code></pre>
    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.
 

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