0 votes
ago in Methoden-Fragen by s304603 (110 points)

Hey! is there a way to set the number of items in multiple dropdowns question based on a specific condition?

I have a free mentions question, where respondents can give many answers as they want. These answers will be the items of the multiple dropdowns question. However, if the respondents give no answer in the Q1, Q2 will show the dropdownlist without an item.

i would be thankful to get some suggestions!

It is actually challenging becauses there is no variable names for the dropdown options.

Bests

ago by SoSci Survey (328k points)
I assume, you're using some PHP code? If you post that, I can (most likely) answer with a useful addition to skip Q2 if Q1 received no answers.
ago by s304603 (110 points)
Thanks! The first question free mentions asks respondents to think of their lives as chapters of a book and title for each chapter. Here, they aren't allowed to add more than 7 chapters.

In the next page, I added this code to create placeholders and check the number of the given chapters:
for ($i = 1; $i <= 7; $i++) {
    $phase = value("A403x" . sprintf("%02d", $i)); // Fetch the title of each phase
    if (!empty($phase)) {
        replace("%sns" . $i . "%", $phase); // Replace placeholder with phase title
    } else {
        replace("%sns" . $i . "%", ""); // Clear unused placeholder
    }
}

$chapterCount = 0;
if (!empty(value('A403x01'))) { $chapterCount++; }
if (!empty(value('A403x02'))) { $chapterCount++; }
if (!empty(value('A403x03'))) { $chapterCount++; }
if (!empty(value('A403x04'))) { $chapterCount++; }
if (!empty(value('A403x05'))) { $chapterCount++; }
if (!empty(value('A403x06'))) { $chapterCount++; }
if (!empty(value('A403x07'))) { $chapterCount++; }
registerVariable('chapterCount', $chapterCount);

// Register the variable for use in routing
registerVariable('chapterCount', $chapterCount);

The multiple dropdowns question ask them about their work in each phase. So the items of this question are %sns_x%. The question will not appear if the first question has not been answered. However, if the respondent gave 2 chapters, the dropdowns question will return empty items but with the dropdown list. I am looking for a solution to set the number of the items to be the same of the number of chapters. Alternativly, I would hide the dropdown list for the empty items.

I am struggling with it and hope you can support me!
Bests

1 Answer

0 votes
ago by SoSci Survey (328k points)

However, if the respondent gave 2 chapters, the dropdowns question will return empty items but with the dropdown list.

Okay, then you can easily tell the dropdown which options to display. By and large, we're talking about this manual: Use Selected Items in Another Question

Based on your code, I add a variable $items (two amendments):

$items = [];
for ($i = 1; $i <= 7; $i++) {
    $phase = value("A403x" . sprintf("%02d", $i)); // Fetch the title of each phase
    if (!empty($phase)) {
        replace("%sns" . $i . "%", $phase); // Replace placeholder with phase title
    } else {
        replace("%sns" . $i . "%", ""); // Clear unused placeholder
        $items[] = $i;
    }
}

And then use this variable to display the dropdown with only relevant items:

question('DD01', $items);

You may also want to replace (!empty($phase)) by (trim($phase) != '') to avoid a blank counting as answer.

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

...