Remove Checkboxes on Unsubscribe | Community
Skip to main content
February 3, 2016
Solved

Remove Checkboxes on Unsubscribe

  • February 3, 2016
  • 1 reply
  • 3497 views

Hello!

We have implemented a Subscription Center to help our users manage the content they receive. You can see the page here​. We would like to have a better user experience by adding the following functionality:

If a user clicks the "unsubscribe" checkbox, all other checkboxes will be unchecked (confirming to the user that they are no longer subscribed to what was checked previously). Lastly, the unsubscribe box should stay checked.

the ID for the unsubscribe checkbox is "unsubscribed". We added the below script and it does not seem to be working.

$("#Unsubscribed").click(function() {        //on click of unsubscribe checkbox

     $(':checkbox').attr("checked", false);     //uncheck all checkboxes

     $("#Unsubscribed").attr("checked", true);      //check the clicked one

});

Any thoughts as to how to fix this? Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Don't use pure jQuery (or any jQuery, IMO) on Marketo forms.  You need to operate within the Marketo Forms API events framework.

MktoForms2.whenReady(function(form){

  var formEl=form.getFormElem()[0],

    unsubscribeField='Unsubscribed',

    unsubscribeEl=formEl.querySelector('#'+unsubscribeField),

    checkboxEls=formEl.querySelectorAll('INPUT[type="checkbox"]');

  unsubscribeEl.onclick = function(e){

    Array.prototype.forEach.call(checkboxEls,function(itm){

        if (itm !== unsubscribeEl && unsubscribeEl.checked) itm.checked = false;

    });

  }

});

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
February 3, 2016

Don't use pure jQuery (or any jQuery, IMO) on Marketo forms.  You need to operate within the Marketo Forms API events framework.

MktoForms2.whenReady(function(form){

  var formEl=form.getFormElem()[0],

    unsubscribeField='Unsubscribed',

    unsubscribeEl=formEl.querySelector('#'+unsubscribeField),

    checkboxEls=formEl.querySelectorAll('INPUT[type="checkbox"]');

  unsubscribeEl.onclick = function(e){

    Array.prototype.forEach.call(checkboxEls,function(itm){

        if (itm !== unsubscribeEl && unsubscribeEl.checked) itm.checked = false;

    });

  }

});

February 4, 2016

Works perfect. Thank you for the note about the Marketo Forms API as well.