0 votes
in SoSci Survey (English) by s160436 (130 points)
edited by s160436

I want to include the dynamic questions in my survey. I have already successfully included one question.

Here, when "Yes" is selected, only then question 5 is visible.
Code for this is:`

<script type="text/javascript">
<!--
var optionA = document.getElementById("CI02_01a");  
var optionB = document.getElementById("CI02_02a");  
var optionC = document.getElementById("CI02_03a");  
var question = document.getElementById("CI03_qst"); 
 
function toogle() {

  if ((optionA.checked)) {

    question.style.display = "";
  } else {
    
    question.style.display = "none";
  }
}
 
 
SoSciTools.attachEvent(optionA, "click", toogle);
SoSciTools.attachEvent(optionB, "click", toogle);
SoSciTools.attachEvent(optionC, "click", toogle);
 

toogle();
// -->
</script>`


Now, I am using similar code on other question, but it is not working:

Here, when "No" is selected, the next question should not be visible.
Code for this question is:

<script type="text/javascript">
<!--
var optionA = document.getElementById("FS01_01a");  
var optionB = document.getElementById("FS01_02a");  
var optionC = document.getElementById("FS01_03a");  
var question = document.getElementById("**FS02_qst**");
 
function toogle() {
 
  if ((optionA.checked) || (optionB.checked)) {
    question.style.display = " ";  
  } else {
    // question is hidden if the "none" option is selected
    question.style.display = "none";
  }
}
 
SoSciTools.attachEvent(optionA, "click", toogle);
SoSciTools.attachEvent(optionB, "click", toogle);
SoSciTools.attachEvent(optionC, "click", toogle);

toogle();
// -->
</script>

`
I tried this at one more page for different question. Was not working with same console error.
Also, tell me how can I define a combined question FS02 and FS03 in javascript as a variable.

Thanks

by SoSci Survey (323k points)
> Was not working with same console error.

What error is displayed, please? It would also be helpful if you posted a pretest URL that leads directly (!) to the respective page.

> how can I define a combined question FS02 and FS03 in javascript as a variable.

Not as a variable, but if you would like to hide/display the question, you can simply use the ID of the first question, i.e., FS02_qst
by s160436 (130 points)
Error message displayed is: Uncaught SyntaxError: Unexpected token '<'
Here is the link to pretest:
https://www.soscisurvey.de/test230191/?act=29Mg2RH5LICqzNM9wSypspgL.

Please select "No" for CI01 to directly jump to error question FS01 and FS02.
Select "Yes" for CI01 to jump to working questions CI02 and CI03.
by SoSci Survey (323k points)
Könnten Sie bitte einen Pretest-Link erstellen, der direkt auf die richtige Sprachversion und Fragebogen-Seite verweist? Danke.

Ein <script type="text/javascript"> haben Sie zu Beginn des Scripts stehen, ja? Ich frage deshalb, weil das in Ihrer Frage scheinbar fehlt.

Und bitte - ganz wichtig - entfernen Sie auch die doppelten Klammern in dieser Zeile:

((optionA.checked))
by s160436 (130 points)
Pretest-Link für funktionierenden Code: https://www.soscisurvey.de/test230191/index.php?i=OTIRQR3TKQ8W&rnd=WJJF (Frage CI02)

Bei Fehlerfrage:
https://www.soscisurvey.de/test230191/index.php?i=FZ7ISRZ6OGW5&rnd=UVOX (Frage FS01)

Ja, das <script type="text/javascript"> ist am Anfang vorhanden. Ich habe die Frage bearbeitet.

1 Answer

+1 vote
by SoSci Survey (323k points)
selected by s160436
 
Best answer

Es liegt an den soppelten Klammern in der JavaScript-Bedingung. Diese interpretiert SoSci Survey als Tooltip, sodass folgender Code herauskommt:

function toogle() {
  // the condition checks: is option A selected?
  if <span class="S2Tooltip anchor marker">optionA.checked) </span><span class="S2Tooltip container"><span class="S2Tooltip tiptext rounded shadow">| (optionB.checked</span></span> {
    question.style.display = " ";  
  } else {
    // question is hidden if the "none" option is selected
    question.style.display = "none";
  }
}

Bitte verwenden Sie einfache Klammern in der besagten Zeile, also z.B.

if (optionA.checked || optionB.checked) {

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...