Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Menghapus Multiple Data Via AJAX Dengan jQuery</title>
- <style>
- body{
- font-family:Arial;
- font-size:12px;
- }
- a:hover{
- padding:3px;
- background:#FF9900;
- text-decoration:none;
- color:#000000;
- }
- a{
- padding:3px;
- text-decoration:none;
- color:#000000;
- }
- </style>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- var url = "data-data.php";
- $("#showdata").load(url);
- $("#selectall").live("click", function()
- {
- $('.chk').attr('checked', this.checked);
- });
- // if all checkbox are selected, check the selectall checkbox
- // and viceversa
- $(".chk").live("click", function()
- {
- if($(".chk").length == $(".chk:checked").length)
- {
- $("#selectall").attr("checked", "checked");
- }
- else
- {
- $("#selectall").removeAttr("checked");
- }
- });
- $("a.hapus").live("click", function() {
- var url = "delete.php";
- var id_array = new Array();
- i=0;
- $("input.chk:checked").each(function(){
- id_array[i] = $(this).val();
- i++;
- });
- $.post(url, {kode: id_array}, function(respon)
- {
- if(respon==1)
- {
- $("input.chk:checked").each(function()
- {
- $(this).parent().parent().remove('.chk').animate({ opacity: "hide" }, "slow");
- });
- }
- });
- });
- });
- </script>
- </head>
- <body>
- <div id="showdata"></div>
- </body>
- </html>
- script untuk data-data.php:
- <?php
- include('koneksi.php');
- $qu = mysql_query("select * from tbl_orang");
- if(mysql_num_rows($qu)<1)
- {
- mysql_query("INSERT INTO tbl_orang (`id_orang`, `nama`) VALUES (NULL, 'Gede Lumbung'), (NULL, 'Budi Raharjo'), (NULL, 'Ivan Gunawan'), (NULL, 'Thomas Lorenzo'), (NULL, 'Roy Suryo'), (NULL, 'Surya Husada'), (NULL, 'Pratama Antara'), (NULL, 'Widya Sari'), (NULL, 'Asti Sri Astuti'), (NULL, 'Omla Ramlan'), (NULL, 'Budi Raharjo'), (NULL, 'Engkong Satu'), (NULL, 'Engkong Dua'), (NULL, 'Engkong Tiga'), (NULL, 'Engkong Muda')");
- }
- ?>
- <table cellpadding="5" cellspacing="0" border="1">
- <tr align="center"><td><a href="#" class="hapus">Hapus</a></td><td>Kode Dosen</td><td>Nama Dosen</td></tr>
- <?php
- $q = mysql_query("select * from tbl_orang");
- $no=1;
- while($b = mysql_fetch_array($q))
- {
- ?>
- <tr align="center">
- <td><input type="checkbox" value="<?php echo $b["id_orang"]; ?>" class="chk"/></td>
- <td><?php echo $b["id_orang"]; ?></td>
- <td><?php echo $b["nama"]; ?></td>
- </tr>
- <?php
- $no++;
- }
- ?>
- <tr><td colspan="3"><input type="checkbox" name="pilih" id="selectall"</td></tr>
- </table>
- script untuk delete.php:
- <?php
- include('koneksi.php');
- $kode_orang=$_POST['kode'];
- $query = mysql_query('delete from tbl_orang where id_orang in ('.$kode_orang.')');
- echo 1;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement