Need help with custom code -delete participant responses for a specific question only | XM Community
Skip to main content
Solved

Need help with custom code -delete participant responses for a specific question only


Hello Qualtrics Community,
I am working on thinking through a future research project where one text response question asks participants to write a very personal response, and then afterward participants respond to several quantitative questions about their response. Due to ethical reasons, I don't actually want to record the information participants type in the text box, but I do want to make sure they take the time to answer the question. I am not sure what is possible, but I am hoping for some guidance on how I either can immediately delete participants response to that specific question only upon submitting their survey, OR how I can record perhaps the number of words or characters participants type without seeing their actual response.
Thanks in advance!

Best answer by SurajK

https://www.qualtrics.com/community/discussion/comment/27264#Comment_27264Yes, use the below code in JS,
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#NextButton").hide();
jQuery("#Buttons").append("")
var qid = this.questionId;


jQuery('#FakeNextButton').click(function(){


var textval = jQuery("div[id='"+qid+"']").find(".InputText").val()


if(textval.length == 0)


{


jQuery("div[id='QR~"+qid+"~VALIDATION']").css("display","block");


jQuery("div[id='QR~"+qid+"~VALIDATION']").html('');


jQuery("div[id='QR~"+qid+"~VALIDATION']").append("Please answer this question");


}


else


{


jQuery("#NextButton").click()
jQuery('#FakeNextButton').hide()


}


});

});

View original

8 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • June 25, 2020

We can create a text area or input text box using HTML code and on click of next button capture the number of words in an embedded data or in hidden qualtrics text input box.


SurajK
QPN Level 3 ●●●
Forum|alt.badge.img+4
  • QPN Level 3 ●●●
  • 181 replies
  • June 25, 2020

nmordini - Use the below code in JS for the required question, it will remove the text which is entered by the respondent and they can move to next question. Make sure the question is optional and if you want to force the respondent to enter the text then you can add custom validation using JS but default force response option of Qualtrics will not allow to move ahead.
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{
var textAns = jQuery(".InputText").val()
if(textAns.length > 0)
{
jQuery(".InputText").val('')
}
}
});


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • June 25, 2020

Agreed with SurajK answer. Also, if you want to capture the number of characters entered by the respondent, then you can use below updated code:
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
if(type == "next")
{
var textAns = jQuery(".InputText").val().trim();
if(textAns.length > 0)
{
Qualtrics.SurveyEngine.setEmbeddedData("TextLength", textAns.length);

jQuery(".InputText").val('')
}
}
});
Make sure you have added "TextLength" embedded data as the first element in survey flow.


  • Author
  • 2 replies
  • June 25, 2020

rondev SurajK Thank you both very much! Would you also be able to show me how to force response in the code as well? I do not have much coding experience.


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1449 replies
  • June 25, 2020

SurajK
QPN Level 3 ●●●
Forum|alt.badge.img+4
  • QPN Level 3 ●●●
  • 181 replies
  • June 25, 2020

https://www.qualtrics.com/community/discussion/comment/27194#Comment_27194You will have to take care of this using fakebutton, add the fakebutton using the below code,
image.pngIn the fakebutton click function add the below code,
var qid = this.questionId;
var textval = jQuery("div[id='"+qid+"']").find(".InputText").val()
if(textval.length == 0)
{
jQuery("div[id='QR~"+qid+"~VALIDATION']").css("display","block");
jQuery("div[id='QR~"+qid+"~VALIDATION']").html('');
jQuery("div[id='QR~"+qid+"~VALIDATION']").append("Please answer this question.");

}
else
{
jQuery("#NextButton").click()
}


  • Author
  • 2 replies
  • June 27, 2020

SurajK
Thank you again for your help. I am probably doing something wrong, but I am unable to get the forced response section to work. Can you explain where this goes within the fakebutton code?
var qid = this.questionId;
var textval = jQuery("div[id='"+qid+"']").find(".InputText").val()
if(textval.length == 0)
{
jQuery("div[id='QR~"+qid+"~VALIDATION']").css("display","block");
jQuery("div[id='QR~"+qid+"~VALIDATION']").html('');
jQuery("div[id='QR~"+qid+"~VALIDATION']").append("Please answer this question.");

}
else
{
jQuery("#NextButton").click()
}


SurajK
QPN Level 3 ●●●
Forum|alt.badge.img+4
  • QPN Level 3 ●●●
  • 181 replies
  • Answer
  • June 29, 2020

https://www.qualtrics.com/community/discussion/comment/27264#Comment_27264Yes, use the below code in JS,
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#NextButton").hide();
jQuery("#Buttons").append("")
var qid = this.questionId;


jQuery('#FakeNextButton').click(function(){


var textval = jQuery("div[id='"+qid+"']").find(".InputText").val()


if(textval.length == 0)


{


jQuery("div[id='QR~"+qid+"~VALIDATION']").css("display","block");


jQuery("div[id='QR~"+qid+"~VALIDATION']").html('');


jQuery("div[id='QR~"+qid+"~VALIDATION']").append("Please answer this question");


}


else


{


jQuery("#NextButton").click()
jQuery('#FakeNextButton').hide()


}


});

});


Leave a Reply