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:
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}}');