twack
17 August 2021 17:49
1
Hi folks,
I have a table in a UI Template Node that contains a list of items. The list is long so I would really like to implement "Check All / Uncheck All" functionality using a checkbox contained within the header row. Does anyone have an example?
TIA
<div>
<input type="checkbox" onClick="toggle(this)">Toggle All</input><br>
<input type="checkbox" name="checkbox" value="bar1">Bar 1</input><br>
<input type="checkbox" name="checkbox" value="bar2">Bar 2</input><br>
<input type="checkbox" name="checkbox" value="bar3">Bar 3</input><br>
<input type="checkbox" name="checkbox" value="bar4">Bar 4</input><br>
</div>
<script language="JavaScript">
function toggle(source) {
let checkboxes = document.getElementsByName('checkbox');
checkboxes.forEach( el => {
el.checked = source.checked;
} )
}
</script>
Explanation :
we trigger the toggle
function with onClick
event
passing in the function this
.. which in this case is the checkbox Toggle All
we get all the checkboxes
we loop through them with forEach
and set each elements check state
to the state of of the Toggle All
element.
system
Closed
31 August 2021 18:06
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.