jQuery Get Multiple Checkbox Value Array
Jquery 12-Nov-2021

jQuery Get Multiple Checkbox Value Array

jQuery get all/multiple checked checkbox value in Array; In this tutorial, you will learn how to get multiple checked checkbox value in jquery using array.

jQuery Get Multiple Checkbox Value Array

Using the jQuery :checked selector, You can get all selected/checked checkbox values in array.

Demonstration of how to get multiple checkbox value in jquery using array

  • First, create a simple HTML file with a checkbox and its value
  • Second, include the jQuery library into this HTML file
  • Third create function to get all checked checkbox values using jquery :checked selector
  • The fourth store checked checkbox value in array using jQuery push() method
  • Fifth print stored array using console.log()

Example jQuery Get Multiple Checkbox Value Array

See the following example to get multiple checkbox value in jquery using array:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Get Values of Selected Checboxes</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> 
<script type="text/javascript">
    $(document).ready(function() {
        $(".btn_click_second").click(function(){
           var favProgramming = [];
           $.each($("input[name='programming1']:checked"), function(){            
                favProgramming .push($(this).val());
            });
 
            alert("My favourite programming languages are: " + favProgramming );
        });
    });
</script>
</head>
<body>
    <form>
        <h3>Select your favorite Programming Languages :</h3>
        <label><input type="checkbox" value="PHP" name="programming1"> PHP</label>
        <label><input type="checkbox" value="Java" name="programming1"> Java</label>
        <label><input type="checkbox" value="Ruby" name="programming1"> Ruby</label>
        <label><input type="checkbox" value="Python" name="programming1"> Python</label>
        <label><input type="checkbox" value="JavaScript" name="programming1"> JavaScript</label>
        <label><input type="checkbox" value="C" name="programming1"> C</label>
        <br>
        <button type="button" class="btn_click_second" style="margin-top: 10px;">Click here to Get Values</button>
    </form>
</body>
</html>