最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Getting SelectedIndexChanged event of checkboxlist using javascript - Stack Overflow

programmeradmin3浏览0评论

I have a checkboxlist control in one of the web application. I want to use javascript to handle the SelectedIndexChanged event.

The checkbox list is like

<asp:CheckBoxList ID="CheckBoxList1" runat="server">
    <asp:ListItem>One</asp:ListItem>
    <asp:ListItem>Two</asp:ListItem>
    <asp:ListItem>Three</asp:ListItem>
    <asp:ListItem>Four</asp:ListItem>
    <asp:ListItem>Five</asp:ListItem>
</asp:CheckBoxList> 

How can I get the SelectedIndexChanged event using javascript?

I have a checkboxlist control in one of the web application. I want to use javascript to handle the SelectedIndexChanged event.

The checkbox list is like

<asp:CheckBoxList ID="CheckBoxList1" runat="server">
    <asp:ListItem>One</asp:ListItem>
    <asp:ListItem>Two</asp:ListItem>
    <asp:ListItem>Three</asp:ListItem>
    <asp:ListItem>Four</asp:ListItem>
    <asp:ListItem>Five</asp:ListItem>
</asp:CheckBoxList> 

How can I get the SelectedIndexChanged event using javascript?

Share Improve this question edited Mar 20, 2012 at 3:42 Joseph 120k30 gold badges184 silver badges237 bronze badges asked Mar 20, 2012 at 3:40 MithunRajMithunRaj 1034 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

On server side.. put the follwoing..

CheckBoxList1.Attributes.Add("onclick", "ChangeCheckBox();");

In client side JavaScript section, implement the following function

function ChangeCheckBox() {}

you can use below code

  document.getElementById('CheckBoxList1').onchange = function () {
                var input = document.getElementById('CheckBoxList1').getElementsByTagName("input")
                for (var i = 0; i < input.length; i++) {
                    if (input[i].type == "checkbox") {
                        if (input[i].checked == true) {
                            alert(input[i].value);//Get all the checked checkboxes
                        }
                    }
                }
            }
发布评论

评论列表(0)

  1. 暂无评论