Posted By

mattvbiggs on 09/28/10


Viewed 4 times

JQuery: Select All/Clear

/ Published in: jQuery

This is used in combination with JavaScript and MVC (hence the ViewData object). If this code is pasted into a MVC View User Control (.ascx) file, it becomes a reusable Select All/Clear control. It was originally written with a C# codebase. It will work in VB as well, with minor changes (i.e. change all square brackets around ViewData to parenthesis). Also, below the closing script tag is code that is used to call the control. Make sure the string value of the first parameter matches the name of the ascx file that contains the script.

  1. <input type="button" id="selectall" value="Select All" /><br />
  2. <input type="button" id="clear" value='<%= ViewData["Label"] %>' />
  4. <script type="text/javascript" language="javascript">
  5. $(document).ready(function() {
  6. $('#selectall').click(function() {
  7. $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
  8. });
  9. $('#clear').click(function() {
  10. $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
  11. });
  12. });
  13. </script>
  16. /*If this code is in a user control, it can be called using the following:
  17. (If the codebase is C#:) */
  18. <% Html.RenderPartial("JQuerySelectAll", ViewData["Label"]="Reset"); %>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.