Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to correctly handle clicks on optional groups. An optional group needs to have a value in 'linkKey' no matter what. Salsa does not do this correctly and sometimes the wrong optional group is recorded. This script assures campaign managers that a clicked optional group either contains the groups_KEY or a zero.
<script type="text/javascript">
// Script to handle clicks on optional groups.
function optionalClick(event) {
var elem =;
elem.value = elem.checked ? elem.getAttribute('alt-value') : 0;
// Find and configure all optional groups.
document.addEventListener("DOMContentLoaded", function() {
Array.from(document.querySelectorAll('input[id^="add_to_groups_KEY"]')).forEach(function(e) {
e.setAttribute('alt-value', e.getAttribute('value'));
e.addEventListener('change', optionalClick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.