jeudi 28 avril 2022

Jquery to allow checkbox after checking a condition?

I have 3 checkboxes like this

by default 3 checkboxes are False Now my requirement is that Both option is allowed to be True only when both First and Second option is true if any of them is false then both option should be unchecked i.e., false

I wanted to acheciver this with Jquery

so my jquery is:

    <input id="#first" type="checkbox" asp-for="first" /> 
    <input id="#second" type="checkbox" asp-for="second" /> 
    <input id="#both" type="checkbox" asp-for="both" /> 
        <script>
                function change() {
                    var firstArg = ($("#first").prop('checked')==true);
                    var secondArg = ($("#second").prop('checked') == true);
                    console.log("---" + firstArg + "------" + secondArg);
                    if (!(firstArg && secondArg))
                    {
                        $("both").prop("disabled", false);
                    }
                }
    function activate() 
{
    change();
    $("#first").bind('change', change());
    $("#second").bind('change', change());
    $("#change").bind('change', change());
    
    }
    
    </script>

But it is not working, can someone please help me with this?




Aucun commentaire:

Enregistrer un commentaire