0

HTML code:

<form method="post" id="cate-form">
            <ul class="expander-list" id="category">
              <li> 
                <div class="radio" style="padding-left:0px">
                  <label>
                     <input type="checkbox" id="all" value="all">
                    All </label>
                </div>
              </li>
              <li> 
                <div class="radio" style="padding-left:0px">
                  <label>
                     <input type="checkbox" name="filter[]" value="active">
                    Active </label>
                </div>
              </li>
              <li> 
                <div class="radio" style="padding-left:0px">
                  <label>
                     <input type="checkbox" name="filter[]" value="inactive">
                    Inactive </label>
                </div>
              </li>
            </ul>
            </form>

jQuery Code:

<script>
        $(document).ready(function(){
            $("#all").click(function() {
              $(':checkbox').prop('checked', this.checked);
            });
            $(":checkbox").change(function(){
                var checked = [];
                alert("it running");
                $('input[name=checkbox] :checked').each(function(){
                    alert("data is pushing inside checked array");
                    checked.push($(this).val());
                })
            })
        });
        </script>

By clicking on all checkbox it selecting all checkboxes. but How can I get a value of an all selected checkboxes at a time.I searched on google for specific this query but nothing helpful is found now please help me for solving a this issue and thanks in advance.

  • 1
    Possible duplicate of [How to retrieve checkboxes values in jQuery](http://stackoverflow.com/questions/786142/how-to-retrieve-checkboxes-values-in-jquery) – Mohammad Oct 08 '16 at 10:46

2 Answers2

0

change

$('input[name=checkbox] :checked')

to

$('input[type=checkbox]:checked') 

since your checkboxes are actually named filter[] but their type is checkbox. your code should work then

Jameson the dog
  • 1,796
  • 1
  • 11
  • 12
0

if you want all value in an array then try this:-

var checkedValues = $('input:checkbox:checked').map(function() {
    return this.value;
}).get();
shubham715
  • 3,324
  • 1
  • 17
  • 27