Introduction
I am describing selection of multiple checkboxes using jQuery. First we make a HTML page design and then we include a jQuery code in the head section. jQuery is basically used for validation but I am using jQuery in this article to select one checkbox and select all other checkboxes.
Code for HTML Page
<html>
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<SCRIPT language="javascript">
$(function () {
// add multiple select / deselect functionality
$("#selectall").click(function () {
$('.name').attr('checked', this.checked);
});
// if all checkbox are selected, then check the select all checkbox
// and viceversa
$(".name").click(function () {
if ($(".name").length == $(".name:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</SCRIPT>
</head>
<body bgcolor="#F5F9C1">
<table border="1">
<tr>
<th colspan="3"><input type="checkbox" id="selectall"/>
Name Rating</th>
</tr>
<tr>
<td width="20" align="center"><input type="checkbox" class="name" name="name" value="1"/></td>



Join the conversation! Your thoughts help the community grow.