Pawan
Pawan

Reputation: 32321

How to get all the names in form of an array whose check-boxes are checked

http://jsfiddle.net/2pypy87p/6/

When selected the checkbox , Select All , the stocks under the greaterquan div are selected . And when i click on the FetchAll button , how to get all the names in form of an array whoses checkboxes are selected .

please let me know how to do this

This is my code

$(document).ready(function() { 
 $('#selecctall').click(function(event) { 
        if(this.checked) 
        { 
        $('#greaterquan .mycheckbox').each(function() {
                this.checked = true;  //select all checkboxes with class "checkbox1"               
            });
        }
        else
        {
 $('#greaterquan .mycheckbox').each(function() { 
                this.checked = false;  //select all checkboxes with class "checkbox1"               
            });
        }
    });


    $(document).on('click', '.fetchall', function(e)
{

    alert('ssssssss');

});

Upvotes: 0

Views: 24

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

You can use :checked selector and .map() like

$(document).ready(function () {
    $('#selecctall').click(function (event) {
        $('#greaterquan .mycheckbox').prop('checked', this.checked)
    });

    $(document).on('click', '.fetchall', function (e) {
        var array = $('#greaterquan .mycheckbox:checked').map(function () {
            return this.nextSibling.nodeValue;
        }).get();
        console.log(array)

    });
});

Demo: Fiddle

Upvotes: 1

Related Questions