Script: Grid Checkboxes - Display Total Checkboxes Selected
This article will help you display the total number of selected Checkboxes in a Grid
Background
You may have scenarios in which you have a Grid setup with Checkboxes and you want to display how many have been selected. This article will show you how.
Instructions
- Program your 'Grid' question with Checkboxes in either orientation
- See article: Add a Question: Grid
- Add the following code to the '</> Add Javascript' field
- See article: Adding JavaScript and/or CSS to a Question
- Line 2 is where you can update the Total Text as needed
var $ = jQuery, totalText = "Total Selected = ", /* TOTAL TEXT TO BE UPDATED */ total = $("input[type='checkbox']:checked").length, footer = $(".cm-instructions:last"); footer.text(totalText + total); $("input[type='checkbox']").change(function(){ total = $("input[type='checkbox']:checked").length; footer.text(totalText + total); });
- For the code to work you need to:
- Click on the '+ Footnote' button.
- Add any character to the field.
- NOTE: Anything you add in this field will be replaced by the total.