Jump to content

Add 'Select All' to check all checkboxes


Recommended Posts

Hi everyone. If you want to add a 'Select All' to check all the checkboxes. You may try the code below on your DataPage:

HTML Block:

 Select All<input onclick="toggle(this);" type="checkbox" />

Footer:

<script language="JavaScript">
function toggle(source) {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i] != source)
checkboxes[i].checked = source.checked;
}
}
</script>

Output:

image.png.acb8c67071d6e643b6d71320a2b73e80.png

 

-Potato

Link to comment
Share on other sites

  • 1 year later...

Thank you, this was really helpful to my workflow but I added some changes since I want to have two select all option on my form.

It seems that the numbering will continue even on the second checkboxes on the for loop in the code.

I'll share it here just in case someone will have a similar workflow.

Here is the code I used:

<script language="JavaScript">
function toggle(source) {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (var i = 0; i < 4; i++) {
if (checkboxes[i] != source)
checkboxes[i].checked = source.checked;
}
}

function toggle2(source) {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (var i = 4; i < 8; i++) {
if (checkboxes[i] != source)
checkboxes[i].checked = source.checked;
}
}
</script>

 

Also I added a new HTML block for the second select all checkbox:

Select All<input onclick="toggle2(this);" type="checkbox" />

 

This is the Output:

image.png.5a7f27963af7220c1b65026dda691ae9.png

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...