senaa
senaa

Reputation: 63

cannot change value in td after event modal bootstrap

I have two rows from the table and I want to change value .

this is my sample table

enter image description here

I want change value judul/title per selected row, when I choose first row then changed the value and worked, after that when I choose second row then changed value and this has a problem that is value from the first row follows the value of the second row enter image description here enter image description here

jquery

$('#tblbuku tbody tr #btnEdit').click(function(){
                    var url  = "buku.form.php";
                    var row  = $(this).closest('tr');
                    var colk = row.find('td:eq(0)').text();
                    var colj = row.find('td:eq(1)').text();

                    $.post(url, {kode: colk, judul : colj} ,function(data) {
                                $(".modal-body").html(data).show();
                                $('#kode').attr('disabled', true);
                                $("#myModal").modal('show');

                                $('#simpan').click(function(){
                                    var ckode    = $('#kode').val();
                                    var ckjudul  = $('#judul').val();

                                    row.find('td:eq(1)').text(ckjudul);

                                });

                    });

                });

php

<?php

$kode  = $_POST['kode'];
$judul = $_POST['judul'];
?>

<form class="form-horizontal" id="form-anggota">
  <div class="control-group">
      <label class="control-label" for="kode">Kode Buku</label>
    <div class="controls">
      <input type="text" id="kode" class="form-control" name="kode"  value="<?php echo $kode ?>">
    </div>
  </div>
  <div class="control-group">
      <label class="control-label" for="judul">judul</label>
    <div class="controls">
      <input type="text" id="judul" class="form-control" name="judul" value="<?php echo $judul ?>">
    </div>
  </div>

</form>

thank you for attention and I will appreciate it

Upvotes: 0

Views: 288

Answers (1)

ikakaotsu
ikakaotsu

Reputation: 21

I had the same problem until I found this answer.

Here's the final solution:

$('#tblbuku tbody tr #btnEdit').off('click').on('click', function(){
    //Your Code...
});

Upvotes: 2

Related Questions