i can select the items of an checkboxlist1

Posted on 2011-10-29
Last Modified: 2012-05-12
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;

Open in new window

Question by:rafaelrgl
    LVL 81

    Expert Comment

    in your browser, right click on your page and choose view source, post it here
    LVL 38

    Accepted Solution

    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;

    Open in new window

    LVL 1

    Author Closing Comment

    perfect. thanks

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now