Wednesday, January 22, 2014

How to Check all the Checkboxes and delete using Jquery?

    <input type="checkbox" id="chkall" onclick="return checkAll(this.checked)" />
  <input type="button" name="button" id="btndel" value="Delete" class="redbutton" onclick="return DeleteFunction()" >

<script src="@Url.Content("~/Content/js/jquery.tablesorter-2.0.3.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/jquery.tablesorter.filer.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.tablesorter.pager.js")"></script>

<script type="text/javascript">
function checkAll(checkedStatus) {
        $("input[class='chkuserid']").each(function () {
            this.checked = checkedStatus;
        });
    }

  function DeleteFunction() {
        var funarray = [];
        $('.chkuserid:checkbox:checked').each(function () {
            funarray.push($(this).val());
        });
     
        if (funarray.length == 0) {
            alert('Please Select Atleast One Record to Delete.');
        } else {
            var t = confirm('Are you sure you want to delete?');
            if (t == true) {
                window.location = '@Url.Action("DeleteFunction","Admin")' + '?FUNC_ID=' + funarray;
            }
            else{return false;}
        }
     
    }
</script>

No comments:

Post a Comment