-2

i have a table which contain <td>'s and im fetching data from db. what i want is remove <td> when user delete data. im newbie in jquery n js. i use bootstrap n able to show modal when user want to delete data. but still i can't remove <td> which user's delete. i know the code is messy and sorry for my english. here is the script:

    foreach ($query as $hasil) {
        if($hasil->status_login=='l')
        {
            $status="Terkunci";
        }
        else if($hasil->status_login=="n")
        {
            $status="Non-aktif";
        }
        else
        {
            $status="Aktif";
        }
        echo '<form method="post" action="proses">';
        echo '<input type="hidden" name="update_admin"><input type="hidden" name="id" value="'.$hasil->akun_id.'">';
        echo '<tr>';
        echo '<td>';
        echo $hasil->akun_email;
        echo '</td><td>';
        echo $hasil->akun_tipe;
        echo '</td><td>';
        echo $hasil->admin_create_date;
        echo '</td><td><select name="status"><option>'.$status.'</option><option>Aktif</option><option>Non-aktif</option><option>Terkunci</option><td><a class="btn btn-danger" type="button" data-toggle="modal" href="#myModal'.$i.'" data-backdrop="true">Hapus admin</a></td><td><button type="submit" class="btn btn-primary" href="#">Simpan</button></td>';
        echo '</form>';





        /**
        form buat ngapus
        **/     
        echo '<form id="rm" method="post" action="proses">';
        echo '<input type="hidden" name="id" value="'.$hasil->akun_id.'">';
        echo '<input type="hidden" name="del" value="true"><input type="hidden" name="lvl" value="admin">';
        echo '<div id="myModal'.$i.'" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
  <span><strong>Pesan</strong></span>
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  </div>
  <div class="modal-body">
    <p>Anda yakin ingin menghapus '.$hasil->akun_email.'</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Batal</button>
    <button class="btn btn-danger">Hapus saja</button>
  </div>
</div>';
echo '<div id="result"></div>';
        echo '</form>';
        $i++;
    }
    echo '</table>';
    echo "<script>
            $('#rm').submit(function() {
            var value = $('td').val();
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serializeArray(),
            success: function(data) {
                $('div[id*=\"myModal\"]').modal('hide');
                $('#result').html(data);
                $('tr').remove(\":contains(value)\");
            }
        })
        return false;
    });";
    echo '</script>';
}
Shail
  • 3,639
  • 1
  • 18
  • 29
Bari
  • 88
  • 3
  • 15

1 Answers1

0

Messy code it is :(

I think the problem is in here :

$('tr').remove(\":contains(value)\");

Try replacing value with the actual content of the td you are trying to remove.

good luck.

andri
  • 1,021
  • 1
  • 9
  • 16
  • however the value is dynamic, so i don't know how to implement – Bari Feb 21 '13 at 04:23
  • you do know what you are doing, don't you? – andri Feb 21 '13 at 04:58
  • i load modal (bootstrap) when user click "Hapus" and in the modal windows there's 2 button. and what i want is when user confirm to delete so the `` which contain that data is removed. but i don't have idea to implement. and also `` has an unique id. – Bari Feb 21 '13 at 05:11
  • in that case you can use the `tr`'s id to remove it, something like this : `$('#your_tr_id').remove()` – andri Feb 21 '13 at 05:14
  • how could i know which user is trying to click. it could be `#data1` or `#data2` etc. – Bari Feb 21 '13 at 05:21
  • how do you know which data to delete on the database? – andri Feb 21 '13 at 05:37
  • i set id value on hidden input – Bari Feb 21 '13 at 05:44
  • if you know how to set that ID, then you should know how to dynamically set the `tr` value or id. pls, comment no more, this is getting too long.... – andri Feb 21 '13 at 05:51