Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda