Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda