Auto answer a text entry question based on embedded data | XM Community
Skip to main content

Hi all, thanks for reading and any help.

I am currently programming a survey where I need a text entry question to autopopulate/auto answer with either a “0” or a “1” based off of an embedded data value, but if the embedded data value does not meet the specifications a participant should answer the question themselves. 

So for example, if the embedded data = blue, the text entry question should autopopulate and save with a “0” and not be asked of the participant. If the embedded data = red, the text entry question should autopopulate and save with a “1” and not be asked of the participant. If the embedded data = green, the participant should answer the question and click the next button themselves.

Based on previous threads, I have mostly figured out how to do this with multiple choice questions, but I am not knowledgeable enough in coding to reconfigure for embedded data/text entry instead. 

Hope this makes sense and is possible! Thanks in advance!

Can you share the code you used for multiple choice questions, thanks.

Regards,

PD


Can you share the code you used for multiple choice questions, thanks.

Regards,

PD

@Prateek.Dang 

Here is what I found in a previous thread which is the closest I’ve been able to find, but still doesn’t function exactly the way I’d like it to so I’m hitting a road block!

)Qualtrics.SurveyEngine.addOnload(function()
{
let selectedRecode = Number("${q://QID1/SelectedChoicesRecode}")//answer from the previous questions
let setAnswer;
if (selectedRecode == 1){
setAnswer = 1 // Recode you want to set
}else if(selectedRecode == 2){
setAnswer = 2
}else if(selectedRecode == 3){
setAnswer = 3
}

this.setChoiceValueByRecodeValue(setAnswer,1)

});

 

Thank you!


Hi @Erin,

I create the below code for you. You just need to change the embedded data name (‘color’) and question id (‘QID81’) to yours.

 

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place your JavaScript here to run when the page loads*/
    
    var defaultText = Qualtrics.SurveyEngine.getEmbeddedData('color');
    
    if (defaultText ==='blue')
    
    {
    
    $('QR~QID81').value = 0;
        this.clickNextButton();
    }
    
    else if (defaultText ==='red')
    
    {
    
    $('QR~QID81').value = 1;
        this.clickNextButton();
    }
    
    
});

 

Didn’t added anything for “Green” as it gets covered in rest cases (any other color or missing embedded data value). Do thorough testing.

 

Regards,

PD


Leave a Reply