mercredi 26 juin 2019

Find whether all input checkbox is checked within a parent div element

I am trying to get the state of two input checkboxes within a div element. I need to set a flag variable to true only if both the checkboxes are checked. If any of the input checkbox is unchecked , then it should be set to false.

I tried this using for loop using the below code

        var oParNode = oNode.ParentNode;
                if (null != oParNode) {

                    for (var i = 0; i < oNode.ParentNode.Nodes.length; i++) {
                        if (oNode.ParentNode.Nodes[i].Checked) {
                            checked = true;
                        }
                        else {
                            checked = false;
                        }
                    }
                }


In this code , Nodes[i] returns the input element. When I check the first checkbox first and the second one next this loop works fine but when I check the second one first , the checked variable is set to true based on the second checkbox value which is executed at last.

Expected: I need to return "checked" to be true only if both checkboxes are checked .

Can somone suggest me on this

Thanks & Regards,

Keerthana.




Aucun commentaire:

Enregistrer un commentaire