i can select the items of an checkboxlist1

hi i have an checkboxlist1 and it's populate by the database, has +- 60 items, i want to create an javascript function to select the boxes or unselect or select some of it. i tryed this and did not worked. any help:

                                                             <a href="#" onclick="javascript:Select(true, 'CheckBoxList1')">Todos</a> | <a href="#" onclick="javascript:Select(false, 'CheckBoxList1')">Nenhum</a>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataTextField="ABREV"    DataValueField="NUMBER" ></asp:CheckBoxList>
<script type="text/javascript">
 function Select(Select, checkBoxListID){    
    for (var i = 0; i < 67; i++) {
        document.getElementsByTagName("ContentPlaceHolder1_" + checkBoxListID + "_0").checked = Select;
  }
}
</script>

Open in new window

LVL 1
rafaelrglAsked:
Who is Participating?
 
Tom BeckConnect With a Mentor Commented:
If you know the id of the container that holds the checkboxes (like ContentPlaceHolder1) then a script like this should work.
<script type="text/javascript">
 function Select(Select, checkBoxListID){ 
    var cph = document.getElementById("ContentPlaceholder1");
    var inputs = cph.getElementsByTagName("input"); 
    var inputId = "";      
    for (var i = 0; i < inputs.length; i++) {
        inputId = inputs[i].id;
        if(inputId.indexOf(checkBoxListID) != -1) {
            inputs[i].checked = Select;
        }
  }
}
</script>

Open in new window

0
 
leakim971PluritechnicianCommented:
in your browser, right click on your page and choose view source, post it here
0
 
rafaelrglAuthor Commented:
perfect. thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.