Skip navigation
All Places > Support > Documents
Log in to create and rate content, and to follow, bookmark, and share content with other members.

Pre-populating email address in subscription forms through visible fields

Document created by 08b21bd4b65c4441fd72920f489da6afa097beae on Jan 2, 2015Last modified by Vishal Sharma on Jun 26, 2018
Version 3Show Document
  • View in full screen mode

Note: Please ensure that you have access to an experienced JavaScript developer, because Marketo Technical Support is not set up to assist with troubleshooting custom JavaScript.

Is this article helpful ?

YesNo


 

The default subscription management records the email address through hidden fields when users click the unsubscribe link in emails.

A simple JavaScript can capture the email parameter and pre-populate a visible field.

Drag and Drop a "Custom HTML" object into the top of the unsubscribe landing page.

Add the following code:

 

<script language="Javascript" src="/js/public/jquery-latest.min.js" type="text/javascript"></script>

<script src="/js/public/jQueryString-2.0.2-Min.js" type="text/javascript" ></script>

<script>

  // to set cookies.  Uses noConflict just in case

  var $jQ = jQuery.noConflict();

  var pEmail = $jQ.getQueryString({ ID: "Email" });

 

document.getElementById("Email").setAttribute("value", pEmail);

 

</script>

Attachments

    Outcomes

      • 8bbaed0da4998202c8510b601c40c1e13191f201

        I couldn't get the above code to work. Checking for Email in the query string kept returning undefined, and the setAttribute method wasn't changing the field values.

         

        After hacking around for too long, I found that .value = pEmail worked better than .setAttribute("value", pEmail). Also, step one has to be checking the DOM is ready, otherwise the script can fire before the form is loaded.

         

        Here's what I ended up with.

         

        <script language="Javascript" src="/js/public/jquery-latest.min.js" type="text/javascript"></script>

        <script src="/js/public/jQueryString-2.0.2-Min.js" type="text/javascript" ></script>

        <script>

        $( window ).load(function() {

          // to set cookies.  Uses noConflict just in case

          var $jQ = jQuery.noConflict();

          var pEmail = $jQ.getQueryString({ ID: "Email" });

         

        document.getElementById("Email").value = pEmail;

         

        });

        </script>

         

        Not sure if that's a better way of doing it, but in my case it's working so far.