How to get selected values of a group of checkboxes

We can use the jQuery :check  selector in combination with the each()  method so as to retrieve the values of all selected checkboxes in a group. The each() method used here simply iterates over all the checkboxes that have been selected/checked.

Let’s give a demonstration of this approach.

The form below presents some favourite sports which we can choose to subscribe to.

Bear in mind that the inputs in the group must have the same name because the syntax to access selected checkboxes looks like

var favorite = [];
$.each($("input[name='sport']:checked"), function(){ 
favorite.push($(this).val());
});

where ‘sport’ is the name of all checkboxes.

Try this demo version on Plunker.

Nguyen Vu Ngoc Tung

I love making new professional acquaintances. Don't hesitate to contact me via nguyenvungoctung@gmail.com if you want to talk about information technology, education, and research on complex networks analysis (i.e., metabolic networks analysis), data analysis, and applications of graph theory. Specialties: researching and proposing innovative business approaches to organizations, evaluating and consulting about usability engineering, training and employee development, web technologies, software architecture.

https://www.itersdesktop.com/author/nvntung/

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.