Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Multiple JS "ReplaceStrings" One is not working

I have a slight understanding of this works, however, not enough to understand what's going on here. I believe it's creating a conflict and rendering one useless.

I'm trying to replace {{aff_id}} with a URL parameter.

This is in ClickFunnels FYI and it's being used in a email submit form.

Here is the code:

<script>
$(document).ready(function () {
var replaceString = "organic";
var replaceString2 = "null";
var urlTerm2 = getURLParameter("aff_id");
var urlTerm = getURLParameter("tid");
if (urlTerm.trim().length > 0 && urlTerm != "null") {
replaceString = decodeURIComponent(urlTerm).replace(/\+/g,' ');
}
$("body").html($("body").html().replace(/\{\{tid\}\}/g,replaceString));
if (urlTerm2.trim().length > 0 && urlTerm2 != "null") {
replaceString2 = decodeURIComponent(urlTerm2).replace(/\+/g,' ');
}
$("body").html($("body").html().replace(/\{\{aff_id\}\}/g,replaceString2));
});
</script>

I'm sure this is something super simple that I'm missing. NAy help would be greatly appreciated!!!

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

My only real critique here is the use of non-descriptive variable names. Like replaceString and replaceString2 are not very helpful. For the do not repeat yourself principle, it might be better to extract the logic as a function. Also, it seems like the regular expressions are more cryptic than actually helpful here. I might write something like this instead.

const replaceTemplate = function (tag, replacment) {
  $("body")
    .html()
    .replaceAll("{{" + tag + "}}", replacment.replaceAll("+", " "));
};

$(document).ready(function () {
  var affId = getURLParameter("aff_id");
  var tid = getURLParameter("tid");

  replaceTemplate("aff_id", affId ? affId : "null");
  replaceTemplate("tid", tid ? tid : "organic");
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!