How to validate the selected value of checkboxlist using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • christyjs
    New Member
    • Jul 2016
    • 19

    How to validate the selected value of checkboxlist using javascript

    Hai i want to display the selected values of checkboxlist in an alert in javascript

    i'm using following code, but it doesn't work.. please help me...



    Code:
    function ChkSelectvalue(ckBoxItems) 
    {
       try 
     { 
           var chkList = ckBoxItems.getElementsByTagName('input');
           var listOfSpans = ckBoxItems.getElementsByTagName('span');
           var chkList1 = chkList.length;
           for (var j = 0; j < chkList1; j++) {
            if(chkList[j].checked==true)
             {
               alert(listOfSpans[j].innerHTML);
             }
           } 
       } catch (e) { };
    }

    Code:
    <asp:CheckBoxList CssClass="ddlFont" ID="chkProvider" Width="325px" runat="server"
                                   onclick="ChkSelectvalue(this);">
                               </asp:CheckBoxList>

    Thanks in advance
    Last edited by Dormilich; Jul 28 '16, 03:32 PM. Reason: please use code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    replace line 14 with
    Code:
    } catch (e) { console.log(e.message); }
    and then check the console output.

    Comment

    • christyjs
      New Member
      • Jul 2016
      • 19

      #3
      Thank you.. But its too didn't work wit me:(

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        it's not supposed to make it work, it's supposed to tell you, when an error occurs, so you can fix it.

        Comment

        Working...