How to Get Multiple Selected Checkbox Values in jQuery

Last Updated on August 15, 2022 by Roshan Parihar

In this tutorial, learn how to get multiple selected checkbox values or checked checkboxes values using jQuery. The short answer is to use the push() function to push elements in an array with join() function to combine them.

You can also use the map() with get() to get the checked checkbox values in jQuery.

Let’s find out with the examples given below.

Method 1: Using push() and join() to Get Multiple Selected Checkbox Values in jQuery

To get the multiple selected checkbox value, you have to first use the click event of jQuery to find the value when someone clicks on the checkboxes. After that, create an array variable and use the push() after each() to add the value of clicked checkboxes one by one. You have to use the val() function to get the value of the clicked checkboxes.

Now, use the join() function to make comma-separated values using jQuery. See the example given below to learn the method.

Output

Virat Kohli
Chris Gayle
Mahendra Singh Dhoni
Sachin Tendulkar
Donald Bradman

The above example contains the checkboxes that you can select multiple by using CTRL of your keyboard and the button element. You can click the multiple checkboxes for multiple selections. On each selection, you will get the value in an alert box.

Method 2: Using map() with get() to Find Values of Checked Checkboxes in jQuery

In addition to the above example, you can also use the map() for checking the values of the checked checkbox. Inside this function, you have to use the val() function to get the values of clicked checkboxes. After that, use the get() to get the collect values in a variable in comma separation.

Output

One
Two
Three
Four
Five

When you select multiple checkboxes and click the button given above, you will get the selected multiple values in an alert box.

You May Also Like to Read

Leave a comment

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.