Reputation: 1
I've trying to customise a script that normally triggers a GTM tag to populate a form's hidden field with a variable (session_url_campaign).
Here is the script:
<script>
(function () {
var value = “{{session_url_campaign}}”
var selector = "input[name='859253_16342pi_859253_16342']"
var field = document.querySelector(selector)
if(field){ field.value = value||"(none)"; }
})();
</script>
I'd like to use this tag to populate all my forms, but unformatunately, my CRM - Pardot - uses form specific names when a same field is use across different form. The name of my hidden field in the above script is 859253_16342pi_859253_16342, but it could be 859253_16342pi_859253_16343 in another form.
Is there a way to use a "OR" logic for my name?
After some research I've found some mention of ||. Would solving my problem as easy as adding between the different values, as below?
<script>
(function () {
var value = “{{session_url_campaign}}”
var selector = "input[name='859253_16342pi_859253_16342||859253_16342pi_859253_16343']"
var field = document.querySelector(selector)
if(field){ field.value = value||"(none)"; }
})();
</script>
Upvotes: 0
Views: 39