Javascript Parameter passthrough | Community
Skip to main content
March 22, 2013
Question

Javascript Parameter passthrough

  • March 22, 2013
  • 5 replies
  • 1922 views

We're having difficulty implementing the javascript to allow passthrough of parameters from a parent page into an embedded marketo landing page form. 

Our CMS (Concrete 5) throws an error when we try to use the provided javascript. the feedback we've gotten is 

"Concrete5 has its own copy of jQuery. So when you load it again from elsewhwere, you end up with 2 copies and duplicate declarations which will cause JavaScript to die and hence the edit bar."

Has anyone experienced this issue with Concrete 5 or another CMS?
 

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

5 replies

March 22, 2013
Patrick, which code are you trying to use? The Munchin tracking code? Please paste the text or a screenshot.
March 22, 2013

I'm using the javascript code provided in this help article

https://community.marketo.com/MarketoArticle?id=kA050000000L55PCAS
 

March 22, 2013
Hi All,

I was trying to add the javascript from the link Patrick posted above to our site. The javascript should be setup correct as per the example. However the problem that arises is that it then conflicts with our sites javascript, rendering us not able to edit our site - sometimes locking us out of the page completely.

For the end user the site looks fine, however even with the javascript added, the variables are not being tracked. 

Thank you in advance for any help.

[CODE]

<script language="Javascript" src="http://discover.certain.com/js/public/jquery-latest.min.js" type="text/javascript"></script><script src="http://discover.certain.com/js/public/jQueryString-2.0.2-Min.js" type="text/javascript" ></script>
<script src="http://discover.certain.com/js/public/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
// to set cookies.  Uses noConflict just in case
var $jQ = jQuery.noConflict();

 // grab the URL parameter (repeat for additional parameters)
var paramvalue1 = $jQ.getQueryString({ ID: "lsch" });
var paramvalue2 = $jQ.getQueryString({ ID: "ls" });

// set the cookies via jquery. expire time is in days (repeat for additional cookies)
$jQ.cookie("engagewp", paramvalue1, {expires: 1, domain: '.certain.com'});
$jQ.cookie("engagewp", paramvalue2, {expires: 1, domain: '.certain.com'});

</script>

[/CODE]

Rafael_Santoni1
Level 5
March 23, 2013
I like to use my own code to do that. This is independent of Marketo and should work for any form fields.

I created this function to parse the url and grab any parameters it may have:

function getQueryString( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec(window.location.href);
  if( results == null )
    return "";
  else
    return results[1];
}

Then I declare a variable for each value I intend to use from the parameters like this:

var firstname = decodeURI(getQueryString('fname')).replace(/\+/g," ");
 
Since you said that you already have jquery running on the site you dont need to re-declare it. Just use it.

Like this:

var $jQ = jQuery.noConflict();
 
  $jQ(document).ready(function() {
       $jQ('#FirstName').attr('value',firstname);
  });

If you are trying to pass the values of ...?fname=John&lname=Doe to fields called FirstName and LastName respectively on the form, the code would like like this within a script tag.

START sample
////////////////////////////

//This function will parse the URL
function getQueryString( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec(window.location.href);
  if( results == null )
    return "";
  else
    return results[1];
}
// Declare variables for ease of use later
var firstname = decodeURI(getQueryString('fname')).replace(/\+/g," ");
var lastname = decodeURI(getQueryString('lname')).replace(/\+/g," ");
 
var $jQ = jQuery.noConflict();
 
  $jQ(document).ready(function() {
       // Assign the values to the fields
       $jQ('#FirstName').attr('value',firstname);
       $jQ('#LastName').attr('value',lastname);
  });

////////////////////////////
END sample

I hope that helps.

Good luck!

Rafael

March 24, 2013
All above are good answers but the root of the problem is the jquery lib and for that you really should either use the lastest required jquery lib for both systems or use the the jQuery.noConflict as this is it intended purpose.

So either don't load the main jquery lib from your cms or the reverse 

OR

use jquery.noconflict

Cheers,
Eric