Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to uncheckbox in data table when button in table click

I have code like this

<table id='data-table'>
 <thead>
   <tr>
     <th>No</th>
     <th>Name Items</th>
     <th>Qty</th>
     <th>Price</th>
     <th>Action</th>
     <th>Check</th>
   </tr>
 </thead>
 <tbody>
   <php foreach($data as $d) : ?>
     <tr>
     <td><?= $no++ ?></td>
     <td><?= $d['name'] ?></td>
     <td><?= $d['qty'] ?></td>
     <td><?= $d['price'] ?></td>
     <td><button type='button' class='btn' name='up'>up</button></td>
     <td><input type='checkbox'></td>
     </tr>
   <php endforeach ?>
 </tbody>

</table>

I want when click button, that qty update data and checkbox if that check then uncheck, I’m use jquery like this but i don’t know how can i uncheckbox when button click.
Thank you in advance

 $('#data-table tbody').on('click', '.btn[name="up"]', function() {
    const row = $(this).closest('tr')[0];
    const qty = Number(row.cells[2].innerHTML);
    const tqty = qty + 1;
    row.cells[2].innerHTML = tqty;
  });

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should use jQuery all the way or not at all

Also you are missing <tr></tr>

$('#data-table tbody').on('click', '.btn[name="up"]', function() {
  const $row = $(this).closest('tr');
  const $cells = $row.find("td");
  const $qtyCell = $cells.eq(2);
  const qty = +$qtyCell.text()
  $qtyCell.text(qty + 1);
  $cells.eq(5).find("[type=checkbox]").prop("checked",false);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<table id='data-table'>
  <thead>
    <tr>
      <th>No</th>
      <th>Name Items</th>
      <th>Qty</th>
      <th>Price</th>
      <th>Action</th>
      <th>Check</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>Name 1</td>
      <td>5</td>
      <td>2.00</td>
      <td><button type='button' class='btn' name='up'>up</button></td>
      <td><input type='checkbox'></td>
    </tr>
    <tr>
      <td>2</td>
      <td>Name 2</td>
      <td>8</td>
      <td>4.00</td>
      <td><button type='button' class='btn' name='up'>up</button></td>
      <td><input type='checkbox'></td>
    </tr>
  </tbody>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading