How to get value of selected checkboxlist items using javascript in asp.net

后端 未结 3 1610
迷失自我
迷失自我 2021-01-14 10:50

I am working on an asp.net project in which i have a checkboxlist which i have bound using

DataTable dt = new Process_Hotels().SelectAllFacilty();                    


        
相关标签:
3条回答
  • 2021-01-14 11:16

    Try debugging

    for (var i = 0; i < checkBoxList1.length; i++) {
    console.log(checkBoxList1[i])
                if (checkBoxList1[i].checked) {
                    checkBoxSelectedItems1.push(checkBoxList1[i].value);
                    //alert('checked:' + checkBoxSelectedItems1.push(checkBoxList1[i].getAttribute("JSvalue")).value);
                    alert('checked - : ' + checkBoxList1[i].value)
                }
            }
    

    Check to see id console.log() gives you any information about the object by pressing F12 on console window. Install firebug plugin for Firefox.

    0 讨论(0)
  • 2021-01-14 11:38

    Try this :

    <script type = "text/javascript">
    
    function GetCheckBoxListValues(chkBoxID)
    {
        var chkBox = document.getElementById('<%= cblHotelFacility.ClientID %>');
        var options = chkBox.getElementsByTagName('input');
        var listOfSpans = chkBox.getElementsByTagName('span');
        for (var i = 0; i < options.length; i++)
        {
            if(options[i].checked)
            {
                alert(listOfSpans[i].attributes["JSvalue"].value);
            }
        }
    }
    
    
    </script> 
    
    0 讨论(0)
  • 2021-01-14 11:42

    I'm new in javascript

    may this code help you

    function CheckBoxCheckOrNot(jobskill) {
    var c = document.getElementById(jobskill).getElementsByTagName('input');
    for (var i = 0; i < c.length; i++) {
        if (c[i].type == 'checkbox') {
    
            if (c[i].checked) {
                alert('checkbox checked');
    
    
            }
            else {
                alert('checkbox unchecked');
            }
        }
    
    
    }
    

    }

    note: jobskill is container id which contain all check boxes.

    0 讨论(0)
提交回复
热议问题