Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change input field back to text
    primarykey
    data
    text
    <p>I have a table and a script that makes each cell an input field when clicked on the edit button at the end of a row. I submit the edited data via Ajax, but I want to make the input field back to normal text after I have edited it.</p> <p>Here is the code:</p> <pre><code>//// EACH CELL INTO INPUT FIELD //// $(document).ready(function(){ $(".edit").click(function(){ var tr = $(this).closest("tr"); tr.find(".td").each(function(){ var name = $(this).attr("title"); var value = $(this).html(); var input = "&lt;input type='text' name='"+name+"' value='"+value+"' /&gt;"; $(this).html(input); }); var submit = "&lt;input type='button' name='Submit' value='Submit' /&gt;"; tr.find(".button").html(submit); }); }); //// END //// //// ONCLICK SUBMIT SEND DATA VIA AJAX //// $(".button input[type=button]").live('click', function() { var data = $('form#muuda').serialize(); // post data using ajax $.ajax({ type: "POST", url: "index.php?leht=kast", data: data, success: function(data) { alert("Andmed muudetud"); // show response from the php script. } }); }); //// END //// </code></pre> <p>HTML:</p> <pre><code>&lt;form id="muuda" method="post" action="#"&gt; &lt;table&gt; &lt;?PHP $sql="SELECT * FROM nimed"; $result = mysql_query($sql)or die(mysql_error()); WHILE ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '&lt;tr class="row"&gt;'; echo '&lt;td class="td" title="id"&gt;'.$row["id"].'&lt;/td&gt;'; echo '&lt;td class="td" title="eesnimi"&gt;'.$row["eesnimi"].'&lt;/td&gt;'; echo '&lt;td class="td" title="perenimi"&gt;'.$row["perenimi"].'&lt;/td&gt;'; echo '&lt;td class="button" title="button"&gt;&lt;button class="edit"&gt;Edit&lt;/button&gt;&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>Here is a picture of the preview:</p> <p><a href="https://lh6.googleusercontent.com/-vVnabdBzFlA/UBjTRhifpWI/AAAAAAAACAo/RvAgpi7x2ik/s488/Ajax%2520submit.jpg" rel="nofollow">https://lh6.googleusercontent.com/-vVnabdBzFlA/UBjTRhifpWI/AAAAAAAACAo/RvAgpi7x2ik/s488/Ajax%2520submit.jpg</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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