0 votes
ago in Methoden-Fragen by s269338 (110 points)
edited ago by SoSci Survey

Hi everyone,

I have an open entries question where each response is stored in its own variable (TE25x01, TE25x02, …).

On the following page, participants should rate their own entries. I’m already able to display their previous answers via HTML, and now I’d like to show a rating slider underneath each answer.

So essentially, for each entry, I want to display a corresponding rating question (AU01, AU02, …) only if the respective TE25x variable is not empty.

Conceptually something like:

if (value('TE25x01') !== '') {
    showQuestion('AU01'); // this command doesnt exist, its just for understanding
}

What is the correct way to conditionally display individual questions based on whether TE25x01, TE25x02, etc. contain values?

Thanks in advance!

1 Answer

0 votes
ago by SoSci Survey (364k points)

Thre are various ways. One would be to replace showQuestion() by show() and copy the code for each combination.

A bit more elegant would it be to work with an array that defines the IDs of the open-ended inputs and the IDs of the questions, and work through that with a FOREACH loop.

Maybe the most elegant option is to also deduct the question ID from the input ID.

$answers = valueList('TE25');
foreach ($answers as $inputID => $answer) {
  if (trim($answer) != '') {
    // Use the number at the end of the input ID, so 01 from TE25x01
    $number = (int)ltrim(substr($inputID, 5), '0');
    $question = id('AU', $number);
    show($question);
  }
}

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

...