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,588
  • 25
  • 31
Rohini
  • 49
  • 2
  • 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
  • 384,651
  • 66
  • 527
  • 531