You are here: Home » JQuery » Multiple Check/Uncheck in Jquery

Multiple Check/Uncheck in Jquery

16 Flares 16 Flares ×

Using JQuery Multiple Check/Uncheck. It will use in multiple delete option.

<!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>Untitled Document</title>
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
   <SCRIPT language="javascript">
$(function(){
 
    // add multiple select / deselect functionality
    $("#selectall").click(function () {
          $('.case').attr('checked', this.checked);
    });
 
    // if all checkbox are selected, check the selectall checkbox
    // and viceversa
    $(".case").click(function(){
 
        if($(".case").length == $(".case:checked").length) {
            $("#selectall").attr("checked", "checked");
        } else {
            $("#selectall").removeAttr("checked");
        }
 
    });
});
</script>
</head>

<body>
<form name="form1" action="" method="post" >
<table>
<tr><td><input type="checkbox" id="selectall"/></td><td>Select All</td></tr>
<tr><td><input type='checkbox' class="case" name='name[]' value="1"  /></td><td>Delhi</td></tr>
<tr><td><input type='checkbox' class="case" name='name[]' value="1"  /></td><td>Mumbai</td></tr>
<tr><td><input type='checkbox' class="case" name='name[]' value="1"  /></td><td>Jaipur</td></tr>
<tr><td><input type='checkbox' class="case" name='name[]' value="1"  /></td><td>Kanpur</td></tr>
<tr><td><input type="submit" name="submit" value="Delete Selected" onclick="return deletemeall();" /></td><td></td></tr>
</table>
</form>
</body>
</html>

For multiple delete

if($_POST['submit'])
	{
     $ff=$_POST['name'];	
     $c=count($ff);
      for($i=0;$i<$c;$i++)
	{
	 $sql = "delete from venue where id='".$ff[$i]."'"; 
	 $result = mysql_query($sql);	
	}
    header("Location: venue.php");
	}

Crate a function deletemeall();.
When function deletemeall(); call, form will Submit and carrying values of Checkbox in a array.
$ff will return all checked box values.
Here i am deleting data from table venue.

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top
16 Flares Twitter 5 Facebook 3 Google+ 3 StumbleUpon 2 Pin It Share 0 LinkedIn 3 16 Flares ×