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

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

  • 25 June 2020
  • 8 replies
  • 28 views

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!

icon

Best answer by SurajK 29 June 2020, 16:39

View original

8 replies

Userlevel 7
Badge +22

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.

Userlevel 5
Badge +4

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('')
}
}
});

Userlevel 7
Badge +22

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.

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.

Userlevel 7
Badge +22

https://www.qualtrics.com/community/discussion/comment/27194#Comment_27194You can just check the force response option for this question.

Userlevel 5
Badge +4

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()
}

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()
}

Userlevel 5
Badge +4

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