jeudi 3 juin 2021

Qualtrics show question based on previous answer using JavaScript

I'm fairly new to JavaScript and have tried to find a solution to my problem but without success.

I have a question (Q4) that should only be displayed if the answer to Q3 is "yes". If I use display logic, Qualtrics will put Q4 on a separate page since it is a "slide" question (the In Page option is unavailable). Since I want Q4 to pop up on the same page as Q3 I figured I need to use a JavaScript option instead.

How can I condition Q4 on the answer of Q3? See example of the (unsuccessful) attempt I have made below. By using .hide() and .show() I can hide and show the question but the if("${QID3" == 1) part is not working.

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place your JavaScript here to run when the page loads*/
    
    // Hide Q as soon as page loads

    $(this.questionId).hide();
    
        // Show Q if condition is met
    if("${QID3" == 1)
        this.questionID().show();    

});

Aucun commentaire:

Enregistrer un commentaire