Get selected checkboxes from comma separated list with jQuery

Basically, there are several method to get selected value into comma sparated. But in today’s era jQuery is most popular JavaScript librery and reduce less line of code.

Using $.map() function we can perform task in a few line of code.

var ele = jQuery(‘input[name=nameofelement]:checked’).map(function(){
return this.value;
}).get().join();

Full Example:

Copy and paste below code into your web page and see how it works.

[gist id=”7783171″]

Leave a Reply

Your email address will not be published. Required fields are marked *