2

I have a list of dynamically populated check boxes with values. This code works but with some unnecessary stuffs like text,free text,free text,etc with the value of my checked checkbox

JS:

$('#save').on('click', function () {
    var val = $(':checked').map(function () {
        return this.value;
    }).get()

    alert(val);
});
kiheru
  • 6,538
  • 22
  • 29
Rohini
  • 49
  • 1
  • 7

1 Answers1

1

Limit your selector to only checbox elements

//or you can use $(':checkbox:checked')
var val = $('input[type="checkbox"]:checked').map(function () {
    return this.value;
}).get()

Demo: Fiddle

Arun P Johny
  • 376,738
  • 64
  • 519
  • 520