jQuery Get Multiple Checkbox Value Array

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 in 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>                            

Demo jQuery Get Multiple Checkbox Value Array

jQuery Get Values of Selected Checboxes

Select your favorite Programming Languages :



Recommended jQuery Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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