21
Dec
09

ajax jquery : php multiple delete item with check box


this tutorial will show you how to delete more than one data with ajax methode using jquery..

first create file, just named it index.php  in this file we create a list of category with check box and a link to delete the category.

you can download the sample  here

index.php

<!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>Multipele Delete</title>
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript">
$(function(){
 $("a.delete").click(function(){
 page=$(this).attr("href");
 ids=new Array()
 a=0;
 $("input.chk:checked").each(function(){
 ids[a]=$(this).val();
 a++;
 })
 if(confirm("Are you sure want to delete?")){
 $.ajax({
 url:page,
 data:"id="+ids,
 type:"GET",
 success:function(res)
 {
 if(res==1)
 {
 $("input.chk:checked").each(function(){
 $(this).parent().parent().remove();
 })
 }
 }
 })
 }
 return false;
 })
})
</script>
</head>

<body>
<table>
<caption><a href="delete.php">delete</a></caption>
<tr>
<td><input type="checkbox" value="1" name="chk[]" /></td><td>category a</td>
</tr>
<tr>
<td><input type="checkbox" value="2" name="chk[]" /></td><td>category b</td>
</tr>
<tr>
<td><input type="checkbox" value="3" name="chk[]" /></td><td>category c</td>
</tr>
<tr>
<td><input type="checkbox" value="4" name="chk[]" /></td><td>category d</td>
</tr>
<tr>
<td><input type="checkbox" value="5" name="chk[]" /></td><td>category e</td>
</tr>
</table>
</body>
</html>

the above code contain jquery code to populate the checked value of check box.

ids=new Array()
 a=0;
 $("input.chk:checked").each(function(){
 ids[a]=$(this).val();
 a++;
 })

after that we sent that value via ajax to php file that run a delete query;

delete.php

// in this file we will run  aquery code. to delete the category by getting the unique id. 
//$id=$_GET['id'].
echo 1;

you can download the sample  here

About these ads

1 Response to “ajax jquery : php multiple delete item with check box”


  1. April 14, 2012 at 6:42 am

    the value of the chk box is not displayed in the delete.php page…
    plz help me..


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Calendar

December 2009
M T W T F S S
« Nov    
 123456
78910111213
14151617181920
21222324252627
28293031  

Blog Stats

  • 33,299 hits

Category


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: