---
title: "Write a jQuery code that selects all the checkboxes in a form when a \"Select All\" button is clicked."  
description: "Write a jQuery code that selects all the checkboxes in a form when a \"Select All\" button is clicked."  
author: "Revati S Misra"  
published: 2023-04-14  
updated: 2023-06-12  
canonical: https://www.mindstick.com/forum/157821/write-a-jquery-code-that-selects-all-the-checkboxes-in-a-form-when-a-select-all-button-is-clicked  
category: "jquery"  
tags: ["jquery", "javascript", "jquery selectors"]  
reading_time: 1 minute  

---

# Write a jQuery code that selects all the checkboxes in a form when a "Select All" button is clicked.

Write a jQuery [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) that selects all the checkboxes in a [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) when a "[Select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) All" [button is clicked](https://www.mindstick.com/forum/12729/how-to-automatically-click-a-html-button-when-asp-dot-net-button-is-clicked).

## Replies

### Reply by Aryan Kumar

Sure, here is the jQuery code that selects all the checkboxes in a form when a "Select All" [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) is clicked:

Code snippet

```plaintext
$(document).ready(function() {
  // Get the "Select All" button
  var selectAllButton = $("#selectAll");

  // When the "Select All" button is clicked
  selectAllButton.click(function() {
    // Select all the checkboxes in the form
    $("input[type=checkbox]").prop("checked", true);
  });
});
```

Here is a breakdown of the code:

- The document.ready() function is used to run the code when the HTML document is ready.
- The <span class="math-inline">\("\#selectAll"\)\ selector is used to get the element with the ID "selectAll". * The `click()` event handler is attached to the "Select All" button. * The `(":checkbox")` selector is used to get all the checkboxes in the form.
- The prop("checked", true) method is used to select all the checkboxes.


---

Original Source: https://www.mindstick.com/forum/157821/write-a-jquery-code-that-selects-all-the-checkboxes-in-a-form-when-a-select-all-button-is-clicked

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
