Hello,
I'm trying to have two different versions of the welcome text of my survey depending on the value of a parameter that is in the URL. I'm using Javascript to read the value of the parameter and with an if-statement it determines what version of the text to display. The parameter is also used to determine the value of question A5 on the next page. However, when I test this and change the language on the first page, the parameter disappears from the URL and the Javascript doesn't function properly anymore. The page shows the text that is under the 'else' condition in my javascript, no matter the parameter that was initially provided. It is almost like it forgot that a parameter was given, but the weird thing is that if I continue with the survey, the value for question A5 that was given is actually saved and shows correctly on the next page. This is the javascript I use:
Code:
<script type="text/javascript">
function getParameter( parameterName ) {
let parameters = new URLSearchParams(window.location.search);
return parameters.get(parameterName);
}
var a = getParameter("A5");
if( a == "A1") {
document.write("version 1")
}
else {
document.write("version 2")
}
</script>
I have tried solving this in a number of ways, but nothing seemed to work. For example, I have tried adding a variable 'b' that I would try to assign the value of question A5 to using either
Code:
var b = "{ A5.NAOK }";
or
Code:
var b = "{ INSERTANS:SGQA }";
and then extending the if-statement to
Code:
if( a == "A1" || b == "A1" ) {
I have tested this with setting the variable 'b' to "A1" manually and then it works, but I can't seem to get that value "A1" from either the URL or from question A5 after I have selected another language. I would be delighted if anyone could help me with this one!
Thanks in advance!
Lars