How to get the checked checkbox value as comma separated value using jquery


Solutions How to get the checked checkbox value as comma separated value using jquery Jquery Join Function

We can get the checked checkbox value with comma separated using jquery. We mostly use these comma separated value for inserting into an array. We have also an tutorial that how to store these value into PHP array.

Demo checked checkbox value using jquery with same class

Red
Blue
Green

Source code get checked checklist using jquery with same class

To get the checked checkbox value using jquery we will assign the same class to the check boxes then using map jquery function we can get the checked checkbox value. We will separate these value by comma using the join function.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="checkbox" class="checklist" value="Red">Red<br> <input type="checkbox" class="checklist" value="Blue">Blue<br> <input type="checkbox" class="checklist" value="Green">Green<br> <button onclick="myFunction()">Get Checked Checkbox Values</button> <script type="text/javascript"> function myFunction(){ var checkedVals = $('.checklist:checkbox:checked').map(function() { return this.value; }).get(); var result = checkedVals.join(","); alert(result); } </script>
Solutions Jquery Join Function Chapter Next »