SOLVED

Re: Javascript Question

Subscribe
Go to solution
Anonymous
Not applicable
The Marketo Article here: https://community.marketo.com/MarketoArticle?id=kA050000000L3Zb provides sample Javascript that you can use on Landing Pages to take an Email token value from a parameter and populate a form field.

Only problem is, if the parameter value isn't present, the Javascript makes the form field default to show the words "undefined".

Is there a small tweak we can make to the JS in that artice, to have the form field prepopulate with no value if the parameter value is missing?
Tags (1)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi Carrie,

Replace your landing page content block that contains the JavaScript code you added to prepopulate the email field on the landing page with 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" });
//--> I added this conditional statement <-- //
     if (! pEmail) {
         //alert('Email address is undefined!');
         document.getElementById("Email").setAttribute("value", '');
     };
</script>

Let me know how that goes!

Reade

View solution in original post

8 REPLIES 8
Anonymous
Not applicable
Reade, you are a superstar!

This worked like a charm 🙂

Thank you!
Anonymous
Not applicable

Hi Carrie,

Replace your landing page content block that contains the JavaScript code you added to prepopulate the email field on the landing page with 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" });
//--> I added this conditional statement <-- //
     if (! pEmail) {
         //alert('Email address is undefined!');
         document.getElementById("Email").setAttribute("value", '');
     };
</script>

Let me know how that goes!

Reade

Anonymous
Not applicable
Hi Reade,

I can't share the actual page, however I've created a replica that functions the same in our own instance for you to take a look at here: http://insights.datarati.com.au/CarrieCommunityTest.html

If you're not cookied, you'll see the field prepopulates with "undefined" - we'd like it to be blank if the Email token isn't present in the URL parameter.

Thanks,
Carrie
Anonymous
Not applicable
Hi Carrie,

Can you share the landing page you are using?

Reade
Anonymous
Not applicable
Hi Reade,

Thanks for providing those two suggestions, I tried both of these, however the "undefined" value was still appearing.

Having said that, I'm not particularly familiar with JS so I'm kind of shooting in the dark a little with where to insert it.

Any ideas?

Thanks,
Carrie
 
Anonymous
Not applicable
Did you try the sample snippets and get it working? If not, can you also share the landing page you are using?
Anonymous
Not applicable

Thanks for your response Reade, the code we're using is the same as that in the article:

<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>

Anonymous
Not applicable
Hi Carrie,

You can try to add some conditional logic using the following examples:

if(typeof variable_here === 'undefined') {
   // your code here.
 };

or 

if(! variable_here) {
   // your code here.
};
If you can share your code here, I may be able to you a bit further.

Hope that helps.