Select Multiple Checkboxes in PHP

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>

<td width="92">Vinod kumar</td>

<td width="42">5</td>

</tr>

<tr>

<td align="center"><input type="checkbox" class="name" name="name" value="2"/></td>

<td>Sharad Gupta</td>

<td>3</td>

</tr>

<tr>

<td align="center"><input type="checkbox" class="name" name="name" value="3"/></td>

<td>Nitin Bhardwaj</td>

<td>2</td>

</tr>

<tr>

<td align="center"><input type="checkbox" class="name" name="name" value="4"/></td>

<td>Aman</td>

<td>1</td>

</tr>

<tr>

<td align="center"><input type="checkbox" class="name" name="name" value="5"/></td>

<td>Rahul Sharma</td>

<td>4</td>

</tr>

</table>

</body>

</html>

 

 Output

To select a checkbox on the top, select all checkboxes, otherwise the checkboxes are selected randomly one by one. This action performs the jQuery function and the function includes HTML code in the head section. We can use this code in our PHP correspondingly.

JQuery use in Php.jpg

JQuery use in Php1.jpg