Link to home
Start Free TrialLog in
Avatar of rafaelrgl
rafaelrgl

asked on

help me with this javascript function to check items on checkboxlist

the first option is working, i can check all, and uncheck all, but what about if i want to select only half of it, and other half.

this code i did is not working for check half. can u help me
<script type="text/javascript">
    function Select(Type, Select, checkBoxListID) {
        var cph = document.getElementById("ContentPlaceHolder1_Panel7");
        var inputs = cph.getElementsByTagName("input");
        var inputId = "";
        if (Type != 1) { 
            for (var i = 0; i < inputs.length; i++) {
                inputId = inputs[i].id;
                if (inputId.indexOf(checkBoxListID) != -1) {
                    inputs[i].checked = Select;
                }
            }
        }
        if (Type != 2) {
            for (var i = 0; i < inputs.length - 40; i++) {
                inputId = inputs[i].id;
                if (inputId.indexOf(checkBoxListID) != -1) {
                    inputs[i].checked = Select;
                }
            }
        }
        if (Type != 3) {
            for (var i = 30; i < inputs.length; i++) {
                inputId = inputs[i].id;
                if (inputId.indexOf(checkBoxListID) != -1) {
                    inputs[i].checked = Select;
                }
            }
        }
    }
</script>

Open in new window

Avatar of MacAnthony
MacAnthony
Flag of United States of America image

It's bad form and confusing to name a parameter and your function the same. How many inputs are there? Block 3 will only work if there are fewer than 30. Also keep in mind if Type is 2, then the first block and last block will run and they seem to be doing similar things.
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial