Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery table read input field value
    primarykey
    data
    text
    <p>I made a place management system where you can create, delete or edit placenames. It's a table where in every row there is a placename an edit button and an delete button. At the end of the table there is a "create new place" button. Now when I click on the "create new place" button then I get a new generated row where I can write the new name, cancel the operation and save the operation.</p> <p>I want know to save an operation which should remove the generated content and create a new row with the name, edit and delete cells. My problem is it only works with one row but if I have two names in operation then the jquery doesnt know on which row I clicked ok to save it.</p> <p>Example:</p> <p>generated Row1= Spain</p> <p>generated Row2= Brasil</p> <p>click ok in row2, row2 removed by jquery, name of row1 generated in placetable = wrong!</p> <p>Here The code</p> <pre><code>&lt;head&gt; &lt;script src="../jquery.js" type="text/javascript"&gt;&lt;/script&gt; $(document).ready(function() { $(".edit").click(function() { var id = $(this).attr("id"); alert("edit "+id); }); $(".delete").click(function() { var id = $(this).attr("id"); alert("delete "+id); }); $("#newbutton").click(function() { $("tr:last").after("&lt;tr&gt;&lt;td&gt;&lt;input style='width: 80%' /&gt;&lt;/td&gt;&lt;td class=ok&gt;OK&lt;/td&gt;&lt;td class=cancel&gt;Cancel&lt;/td&gt;&lt;/tr&gt;").ready(function() { $(".cancel").live("click", function() { $(this).parent().remove(); }); $(".ok").click(function() { var name = $(this).val(); $(this).parent().remove(); $("tr .edit:last").after("&lt;tr&gt;&lt;td&gt;"+name+"&lt;/td&gt;&lt;td class=edit&gt;edit&lt;/td&gt;&lt;td class=delete&gt;delete&lt;/td&gt;&lt;/tr&gt;"); }); }); }) }); &lt;/script&gt; &lt;/head&gt; &lt;table border=1 id=table&gt; &lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Bombai&lt;/td&gt;&lt;td id=1 class=edit&gt;edit&lt;/td&gt;&lt;td id=1 class=delete&gt;delete&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;London&lt;/td&gt;&lt;td id=2 class=edit&gt;edit&lt;/td&gt;&lt;td id=2 class=delete&gt;delete&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Rom&lt;/td&gt;&lt;td id=3 class=edit&gt;edit&lt;/td&gt;&lt;td id=3 class=delete&gt;delete&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;&lt;label id=newbutton&gt;New Place&lt;/label&gt; </code></pre>
    singulars
    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