$(document).ready(function() { $(".category-project-control-helpguide-view-contents").load("/index.php/rental/ajax"); //add all $(".category-project-item-display-add-all").click(function() { var $item_id = new Array(); var $inc = 0; var $allChecked = 1; $(".category-project-item-display-toggle").each( function() { if ($(this).attr('checked') == false){ $allChecked = 0; } }); //if at least one is not checked... check all if ($allChecked == 0){ $allChecked = 1; $(".category-project-item-display-toggle").each( function() { $(this).attr('checked', true); $item_id[$inc] = $(this).attr("id"); $inc++; }); //ajax call ----------------------------- $.ajax({ type: "POST", data: "item_id[]=" + $item_id + "&list_action=insert", url: "/index.php/rental/ajax", success: function(del){ //alert($item_id + " Has been added!"); $(".category-project-control-helpguide-view-contents").load("/index.php/rental/ajax"); } }); //ajax end ------------------------------ } //if they are all checked.. then uncheck all else{ $allChecked = 0; $(".category-project-item-display-toggle").each( function() { $(this).attr('checked', false); $item_id[$inc] = $(this).attr("id"); $inc++; }); //ajax call ----------------------------- $.ajax({ type: "POST", data: "item_id[]=" + $item_id + "&list_action=delete", url: "/index.php/rental/ajax", success: function(del){ //alert($item_id + " Has been removed!"); $(".category-project-control-helpguide-view-contents").load("/index.php/rental/ajax"); } }); //ajax end ------------------------------- } }); //on click $(".category-project-item-display-toggle").click(function() { ////alert($(this).attr("name") + " Has been added!"); var $item_id = new Array($(this).attr("id")); if ($(this).is(':checked')){ $list_action = "insert"; } else { $list_action = "delete"; } //ajax call ----------------------------- $.ajax({ type: "POST", data: "item_id[]=" + $item_id + "&list_action=" + $list_action, url: "/index.php/rental/ajax", success: function(del){ //alert($item_id + " Has been removed!"); $(".category-project-control-helpguide-view-contents").load("/index.php/rental/ajax"); } }); //ajax end ------------------------------ }); //on click item detail page $(".item-display-toggle-item-detail").click(function() { ////alert($(this).attr("name") + " Has been added!"); var $item_id = new Array($(this).attr("id")); $list_action = "insert"; //ajax call ----------------------------- $.ajax({ type: "POST", data: "item_id[]=" + $item_id + "&list_action=" + $list_action, url: "/index.php/rental/ajax", success: function(del){ //alert($item_id + " Has been removed!"); $(".category-project-control-helpguide-view-contents").load("/index.php/rental/ajax"); } }); //ajax end ------------------------------ }); });