Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

64
Vistas
Add values into hidden form fields using JS

I am trying to insert a string into the form hidden field using JS and google tag manager.

This is the script/method (worked on a bunch of different forms)

(function(){

var selector1 = $('[id="label-utm_source-f7d353cc-c056-400e-a41a-2b022eaf4340_7665"]') 
$(selector1).val('{{Read UTM Medium cookie}}');

})();

</script>

or

var selector1 = $('input name="utm_original_lead_source"') 
$(selector1).val('{{Read cookie-UTM source}}');

And nothing worked. Any idea what I'm missing here ?

Thank you!

This is the form field:

enter image description here

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

A css selector is actually a string. So this cannot work:

var selector1 = $('[id="label-utm_source-f7d353cc-c056-400e-a41a-2b022eaf4340_7665"]') 
$(selector1).val('{{Read UTM Medium cookie}}');

it should be something like this:

var selector1 = '*[id="label-utm_source-f7d353cc-c056-400e-a41a-2b022eaf4340_7665"]';
$(selector1).val('{{Read UTM Medium cookie}}');

This is also wrong:

var selector1 = $('input name="utm_original_lead_source"') 
$(selector1).val('{{Read cookie-UTM source}}');

And should be like this:

var selector1 = 'input[name="utm_original_lead_source"]';
$(selector1).val('{{Read cookie-UTM source}}');
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos