vendredi 19 juin 2020

Restrict deleting all selected checkbox if it is last record

i have list of line items dynamically populating from database. I want to restrict deletion if single line item exists.

Now it is getting deleted without checking.

Here is my code

<script>
    $(document).ready(function() {
        $("form#form1").submit (function() {
           if($('input[type="checkbox"]:checked').length) {
                return true;
            } 
            else {
                alert("Please select at least one item !");
                return false;
            }           
        });

    });
</script>

my form

<form class="form" id="form1" action="" method="post">

</form>

and the checkbox is

<input class='check_all' checked="checked" type='checkbox' onclick="select_all()"/>

I tried getting length like this

$('input[type="checkbox"]:checked').length) = 1 
{
alert("Can't delete!");
                return false;
}

But it did't check.

Where i am doing wrong i am not getting




Aucun commentaire:

Enregistrer un commentaire