Skip to content

Getting Checkbox Value in jQuery

  • by

In HTML Form, the dropdown, checkbox type fields have an array of value. In this post, we are going to see how to get the array of selected Checkbox Value in jQuery

In this example, we are using jQuery each() to get each checked value in an array. Then this array values will be shown using a Javascript alert box. This will be used to validate checkbox field.

Creating HTML Form with Checkboxes

This HTML shows a form containing a list of frs with checkbox field.

<form name="frmFruit" id="frmFruits" action="" method="post">
  <div id="lang-list">
    <div class="frm-label">List of Fruit Names:</div>
      <input type="checkbox" name="fruit" id="fruit1" value="Apple" >
      <input type="checkbox" name="fruit" id="fruit2" value="Apricot" >
      <input type="checkbox" name="fruit" id="fruit3" value="Banana" >
      <input type="checkbox" name="fruit" id="fruit4" value="Cherry" >
      <input type="checkbox" name="fruit" id="fruit5" value="Coconut" >
      <input id="btnSubmit" type="button" value="Submit" />
Previously, we have seen an example to implement Update/Delete Multiple Rows using PHP

Getting Checked Values using jQuery

This jQuery script is used to get the checked value from the form checkbox field using jQuery each(). Using this jQuery function it runs a loop to get the checked value and put it into an array. Then the selected values with the count will be shown using an alert box.

<script src=""></script>
<script language="javascript" type="text/javascript">
	$(document).ready(function () {
	var selectedFruit = new Array();
	$('input[name="fruit"]:checked').each(function() {
	alert("Number of selected Fruits: "+selectedFruit.length+"\n"+"And, they are: "+selectedFruit);


Thus we have learned how to Getting Checkbox Values in jQuery. This article described the checkbox type fields have an array of value.

I hope this example helped to create your own code to manage PHP sessions and time.

Leave a Reply

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