0

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.

2
  • 1
    Where do you need to display the values? Commented Nov 28, 2017 at 14:27
  • @MHRasel I just want to display in alert only for testing Commented Nov 28, 2017 at 14:33

1 Answer 1

2

you only need to fix your selector

try this

$("input[type=submit]").click(function () {
     $('input[type="checkbox"]:checked').each(function () {
        alert("Checkbox: " + $(this).val());
     });
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.