Stop second lightbox from appearing | Community
Skip to main content
New Participant
May 23, 2023
Solved

Stop second lightbox from appearing

  • May 23, 2023
  • 1 reply
  • 4108 views

I have a lighbox that opens when one of the download buttons is clicked but I've noticed a second empty lightbox opens in the top left corner too, I'm guessing it's to do with the 'show' command on both the form and the onSuccess but what do I need to change to prevent this second one from appearing?

 

<script src="//go.wilmingtonplc.com/js/forms2/js/forms2.min.js"></script> <form id="mktoForm_13497"></form> <script>var instanceURL = "//go.domain.com", munchkinId = "000-XXX-000", formId = 13497; var gateLinks = document.querySelectorAll(".lightboxGated"), ready = function(form){ form.addHiddenFields({ "axcoLastReportID" : this.id }); MktoForms2.lightbox(form).show(); }; [].forEach.call(gateLinks,function(link){ link.addEventListener("click",function(e){ MktoForms2.loadForm( instanceURL, munchkinId, formId, ready.bind(this)); e.preventDefault(); }); }); </script> <script>MktoForms2.whenReady(function (mktoForm) { MktoForms2.lightbox(mktoForm, { onSuccess: showThanksEl }).show(); function showThanksEl(vals, thankYouURL) { var formEl = mktoForm.getFormElem()[0], thanksEl = document.createElement("DIV"); thanksEl.innerHTML = "<div class='popUp'><h2 style='color: #ff4338; text-align: center;padding-top:10px;'>Thank you! </h2><p style='color: #0C2340; font-size: 16px; text-align: center;padding:20px;'>Your selected report has been sent to the email address provided</p></div>"; formEl.parentNode.replaceChild(thanksEl, formEl); return false; } });</script>

 

 

 

Best answer by SanfordWhiteman

Your problems are a bit broader than that. You also are creating a new Marketo form object every time the person clicks, but you should be using the same shared form every time. See this CodePen demo: nation/336022 - MktoForms2 :: Shared lightbox, dynamic hidden field.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
May 23, 2023

Your problems are a bit broader than that. You also are creating a new Marketo form object every time the person clicks, but you should be using the same shared form every time. See this CodePen demo: nation/336022 - MktoForms2 :: Shared lightbox, dynamic hidden field.

trevlarrrAuthor
New Participant
May 24, 2023

Thanks @sanfordwhiteman , assume that's the difference between the var and const keyword?

Also though, since updating with that code the thank you message no longer appears, on filling out the form it hangs on 'please wait' (or download if it's a known user) but doesn't progress to the thank you message (although the email does fire off in the background so it is still registering the success). The live page is here,  do you know what could be stopping that now?

trevlarrrAuthor
New Participant
May 24, 2023

Never mind, figured out there was a } in the wrong place, below the onSuccess line, moved it to after return false; and now the thank you message displays perfectly.