mardi 28 novembre 2017

Loop through checkbox and display the value of checkbox

I'm looping through multiple checkboxes and inside the loop I need to be able to display value of checboxes are checked.How to do that?

So far, this is my code:

$("input[type=submit]").click(function () {
   var answer = $("#SelectedAnswer").val();
   $("input:checked").each(function () {
      alert("Checkbox: " + answer);
   });
});

My checkbox is looping in table that hold the value

<table class="table" id="polo">
<thead>
    <tr>
        <th colspan=""></th>
        <%
        for(int a = 1; a < 4; a++){         
        %>
        <th>PO <%=a %></th>
        <%
        }
        %>
    </tr>
</thead>
<tbody>
    <%
        for(int i = 1; i < 4; i++){         
    %>
    <tr>
        <td id="loid">LO <%=i %></td>
        <%
        for(int x = 1; x < 4; x++){         
        %>
        <td id="sempo"><input type="checkbox" name="poid" id="poid" value="po <%=x %>" class="checkbox-primary"></td>
        <%
        }
        %>
    </tr>
    <%
        }
    %>
</tbody>

Sorry for the newb question. I'm kinda new to jquery.




Aucun commentaire:

Enregistrer un commentaire