javascript - Get Edited TD values in jQuery

465

I have an HTML table whose span is populed by PHP variables. The table is showing up pretty well, showing the data present in the database. The following is the table row, which is wrapped inside a PHP while loop.

<table id="sample_editable_1" role="grid" aria-describedby="sample_editable_1_info">
 <tr role="row" >
  <td contenteditable="false" >
   <span > </span>
  </td>
  <td contenteditable="false">
   <span ><?php echo $itid1; ?></span>
  </td>
  <td contenteditable="false">
   <span ><?php echo $name1; ?></span>
  </td>
  <td contenteditable="false">
   <span > <?php echo $price1; ?></span>
  </td>
  <td contenteditable="false">
   <span ><?php echo $qty1; ?></span>
  </td>
  <td>
   <button value="edit" href="javascript:;"> Edit </button>
  </td>
  <td>
   <button href="javascript:;"> Delete </button>
  </td>
 </tr>
</table>

The following is jQuery function I am using to pull the Data.

$('#sample_editable_1').on('click', '.pr_edit', function() {
  console.log("here");
  var currentTD = $(this).parents('tr').find('td');
  $.each(currentTD, function() {
    $(this).prop('contenteditable', true);
  });

  var ino = $(this).closest('tr').find("span.itid").text();
  var iname = $(this).closest('tr').find("span.name").text();
  var iprice = $(this).closest('tr').find("span.price").text();
  var iqty = $(this).closest('tr').find("span.qty").text();
});

However, I am not able to retrieve the values from the fields that are edited. The rest of the TR cells are Okay. How do I retrieve modified values from the Table cells I have edited?

IMPORTANT NOTE:

I am able to obtain values that are from unedited TR cells. The jQuery selectors are correct.

People are also looking for solutions to the problem: php - Update data on a page without refreshing

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.