Using lead tokens in javascript causing errors | Community
Skip to main content
Matt_Stone2
New Participant
October 23, 2014
Solved

Using lead tokens in javascript causing errors

  • October 23, 2014
  • 14 replies
  • 3040 views
I'm trying to set javascript variables using lead tokens, but it looks like the tokens spit out html entity versions (e.g. instead of "Matt" it spits out "Matt"), which cause all sorts of problems with the script.

Has anyone encountered this before?
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 Matt_Stone2
In case anyone finds this thread, I wanted to share the results of my discussion with support:

After being escalated to a higher-tier of support, I was informed that "...engineering was able to respond and let me know that this is unfortunately the intended behavior at this time. The value that is returned is due to us performing an HTML escape on tokens so those are the escape characters (ascii)."

Despite this, you can decode the characters to achieve the desired results with something like this:

var test = "{{lead.First Name}}";  
var decoded = $('<textarea/>').html(test).text();


And then you'll be left with the "decoded" variable that outputs properly.

14 replies

Kenny_Elkington
New Participant
October 27, 2014
Hey Matt,

Sorry I didn't get back to you sooner.  This doesn't look right, can you log a support case with the info which you've provided here and an example lead and landing page where you've seen this occurring?
Matt_Stone2
New Participant
October 27, 2014
Bump -- any ideas?
Matt_Stone2
New Participant
October 23, 2014
<script type="text/javascript">
$( document ).ready() {
  var testEmail = "{{lead.First Name}}";  
  console.log("User ID: " + testEmail);
}
</script> 


Ignore the fact that the variable is called testEmail... originally I was trying to pass the lead's email and switched it to first name when I ran into trouble.

When the page loads, this is what you see in the source:
<script type="text/javascript">
$( document ).ready() {
  var testEmail = "&#77;&#97;&#116;&#116;";  
  console.log("User ID: " + testEmail);
}
</script>

Also might be worth noting that in the above case, I'm using an HTML element via the landing page builder. However, I have also tried adding this code directly to the landing page template and had the same result.
Kenny_Elkington
New Participant
October 23, 2014
Hey Matt,

What does the script look like in your page html?