Dear Community,
I have a website in English and German and a Typeform embed. I need to open a different Typeform ID depending on the language. I successfully embedded a Typeform on our website, but I’m having issues opening the correct popup based on the language. I can see on a browser console that I’m successfully getting the Typeform ID depending on the language of the website, but I’m not able to set this attribute to the Typeform embed.
Here is the script I have on the website:
<!-- Select Typeform form based on the language. START -->
<script src="//cdn.weglot.com/weglot.min.js"></script>
<script>
Weglot.on("switchersReady", function(initialLanguage) {
console.log("the switchers are ready, I can tweak them")
let listTypeformData = {
'en': 'guhcBFUy',
'de': 'IzwdgMwJ'
};
var currentLanguage = Weglot.getCurrentLang();
let typeformData = listTypeformData[currentLanguage];
console.log(typeformData);
var a = document.getElementById("tf-B2B-EN-1");
a.setAttribute("data-tf-popup", typeformData);
})
</script>
<!-- Select Typeform form based on the language. END -->
And here is the embed script:
<button
id="tf-B2B-EN-1"
data-tf-popup="guhcBFUy"
data-tf-iframe-props="title=Join our community of hand-picked creators."
style="
all:unset;
font-family: Sahar,Helvetica,Arial,sans-serif;
display: inline-block;
max-width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
background-color: #E53C4E;
color: #FFFFFF;
font-size: 16px;
line-height: 16px;
font-weight: 600;
text-align: center;
text-decoration:none;
border-radius: 6px;
padding-right: 50px;
padding-left: 50px;
padding-top: 17px;
padding-bottom: 15px;
border: 1px solid #E53C4E;
margin-top: 10px;
">Join Now</button>
<script src="//embed.typeform.com/next/embed.js"></script>
What I’m trying is to set the attribute data-tf-popup when the language changes.
I’ve been trying to solve this for a couple of days now, unsuccessfully sadly.
Any help will be very appreciated!
Thanks!