Subscription Center - Check/Uncheck All Javascript

Anonymous
Not applicable

Recently someone on my team asked me for a bit of help in writing some JavaScript to check and uncheck the boxes on a subscription center when someone selects the Unsubscribe from All checkbox. You would think this code would be easy to find just floating around because so many people need it, but I actually couldn't find it all that easily. Since I'm probably not the only one who needs this code, why not share it?

Code to Check All Subscription Boxes

Make sure you update the field names in the quotes to match the field names in your instance, beginning with 'selectAll', which is the checkbox that, when selected, should populate all of the other checkboxes. Obviously, you should also remove any rows you don't need because you have less options than this example.

<script>

MktoForms2.whenReady(function (form) {

document.getElementById('selectAll').onclick = function() {

  if ( this.checked ) {

document.getElementById('mktosupplychainmanagement').checked = true;

document.getElementById('mktosmallmolecules').checked = true;

document.getElementById('mktobiologics').checked = true;

document.getElementById('mktoevents').checked = true;

document.getElementById('mktocommercialproductsupply').checked = true;

document.getElementById('mktoproductdevelopment').checked = true;

document.getElementById('mktogeneralmarketingcommunications').checked = true;

document.getElementById('Unsubscribed').checked = false;

  } else {

  // Did not Globally Subscribe

  }

  }

});

</script>

Code to Uncheck All Subscription Boxes

<script>

MktoForms2.whenReady(function (form) {

document.getElementById('Unsubscribed').onclick = function() {

  if ( this.checked ) {

document.getElementById('mktosupplychainmanagement').checked = false;

document.getElementById('mktosmallmolecules').checked = false;

document.getElementById('mktobiologics').checked = false;

document.getElementById('mktoevents').checked = false;

document.getElementById('mktocommercialproductsupply').checked = false;

document.getElementById('mktoproductdevelopment').checked = false;

document.getElementById('mktogeneralmarketingcommunications').checked = false;

document.getElementById('selectAll').checked = false;

  } else {

  // Did not Globally Unsubscribe

  }

  }

});

</script>

3950
12
12 Comments