jeudi 30 avril 2015

JQuery not selecting all in from checkbox

I cannot seem to get my JQuery working. I have attached my view which has a loop that shows every model in a table format. Each model has a checkbox beside it. The table head also has a checkbox item name/id as checkAll. I have referenced my JQuery script and added my function. I cannot get the function to work, when I click on the checkAll check box nothing happens. I'm extremely new to JQuery and cannot work this one out?

@model IEnumerable<MVC_Example2___ADO.Models.Employees>

@{
    ViewBag.Title = "Delete";
}
<script src="http://ift.tt/yyiuBY" type="text/javascript" >
</script>
<script type="text/javascript">
    $(function () {
        $("#checkAll").click(function () {
            $("input[name='EmployeeIDToDelete']").click(function () {
                if ($("input[name='EmployeeIDToDelete']").length == $("input[name='EmployeeIDToDelete']:checked").length) {
                    $("#checkAll").attr("checked", "checked");
                }
                else {
                    $("#checkAll").removeAttr("checked");
                }
            })
        })
    })
</script>
<html>
<body>
    @using (Html.BeginForm())
    {
        <table align="center" border="1" style="border:ridge;">
            <thead>
                <tr>
                    <td><input type="checkbox" id="checkAll" name="checkAll" /> </td>
                    <td>Photo</td>
                    <td>Name</td>
                    <td>Gender</td>
                </tr>
            </thead>
            <tbody>
                @Html.EditorForModel()
            </tbody>
        </table>
        <input type="submit" name="submit" value="Delete Entries" />
    }
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire