I have a table in CRUD loaded from database, I want table rows to be editable by converting table cell to input field preserving cell text as input value. I am using jQuery for that.
So far, I can add input field inside <td> tag. But data from all the cells becomes value of each input instead of becoming value of their respective input fields.
Here is my code...
$("#parEdit").click(function() {
$(this).text("Update");
$(this).closest('tr').children().wrapInner('<input type="text" value = ' + $('td').text() + '></input>');
})
My table looks like this...
| ID | Name | Position | Marks | Edit |
|---|---|---|---|---|
| 1 | Ahmad | 6th | 525 | Edit Button |
After pressing the Edit button, the output is like this...
| ID | Name | Position | Marks | Edit |
|---|---|---|---|---|
| 1Ahmad6th525 | 1Ahmad6th525 | 1Ahmad6th525 | 1Ahmad6th525 | Update Button |