Autofill the answer of a question based on answer of previous question | Experience Community
Skip to main content

Autofill the answer of a question based on answer of previous question

  • Jan 12, 2022 11:58 AM UTC
  • 6 replies
  • 2092 views

Forum|alt.badge.img+3

Hello all. Is it possible to autofill the answer of a question based on the answer of a previous question? I have uploaded a screenshot. For example, all the respondents who choose tennis as a favorite sport, the answer of the next question will be autofilled with 'Roger Federer', without answering the question. The question will appear to other respondents who did not choose tennis as a favorite sport
Thank you :)
Capture556.PNG

6 replies

Rudi
QPN Level 3 ●●●
Forum|alt.badge.img+16
  • QPN Level 3 ●●●
  • Jan 13, 2022 10:43 AM UTC

Hi Appostolos,
yes you can achieve this by writing the below code into the question you want to set automatically
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)

});
Hope this helps

Rudi



Forum|alt.badge.img+3
  • Author
  • QPN Level 1 ●
  • Jan 14, 2022 9:57 AM UTC

Hello Rudi, thank you for your answer. Unfortunately it does not work for me. I have no knowledge of javascript though. The whole idea is respondents who choose Tennis in question 1, they won't need to answer question 2, they will be directed to question 3 but their answer in question 2 will be autollfilled with choice 1 ('Roger Federer'). All the other respondents who choose Football or Volleyball, they will answer the question 2 and they can choose anything they want.

Thank you very much anyway


Rudi
QPN Level 3 ●●●
Forum|alt.badge.img+16
  • QPN Level 3 ●●●
  • Jan 17, 2022 8:03 AM UTC

Hi Apostolos,

for skipping the question you need to insert this.clickNextButton()

Best regards

Rudi


Forum|alt.badge.img+3
  • Author
  • QPN Level 1 ●
  • Jan 25, 2022 9:57 AM UTC

Thank you Rudi


  • Sep 2, 2022 9:22 PM UTC

https://community.qualtrics.com/XMcommunity/discussion/comment/42907#Comment_42907I came across the same issue and the only difference is that my question 1 is a multiple response question, meaning respondents can select "Tennis" along with other options. However, as long as "Tennis" is selected, these respondents won't see question 2 and their answer in question 2 will be autofilled with choice 1 ('Roger Federer'). " I adjusted your codes to be like below but it still doesn't work and everybody would skip question 2 no matter what they choose at question 1. How can I fix the codes? Thank you very much!
Qualtrics.SurveyEngine.addOnload(function()
{
let selectedRecode = Number("${q://QID10/SelectedChoicesRecode}")
let setAnswer;
if (selectedRecode == 1){
setAnswer = 1
}

this.setChoiceValueByRecodeValue(setAnswer,1)
this.clickNextButton()

});


Forum|alt.badge.img+1
  • Sep 22, 2022 12:32 PM UTC

jmaddoxRudi Apostolos99 Li_zh TomG
did you get this sorted in the end? i.e working for multiple choice question repopulation?

I have tried the solution posted above to no success, I have posted some new issues identified on this post: https://community.qualtrics.com/XMcommunity/discussion/22392/how-do-you-get-the-embedded-data-from-coded-questions-to-populate-a-follow-up-survey#latest