How can I deselect a response of a slider based from a question on the same page? | XM Community

How can I deselect a response of a slider based from a question on the same page?


Userlevel 1
Badge +5

I have a slider question (QID64 - "competence of the trainers?") and need to hide and deselect a response based from the question above it. I already have the code to hide but I can't deselect the response.
If the respondent selected "online" then the next question should be hidden and the response should be deleted. Those 2 questions should be on the same page so I cannot use display logic since it is not working with slider questions.
image.pngHere's my current code:
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

var that=this.questionId;

  jQuery("#QID464").hide();

  jQuery("#"+ this.questionId+" input[type='radio']").on('change',function(){ 
    if(jQuery("[id='QR~"+that+"~1']").prop('checked')){
     jQuery("#QID464").show();
    }else{
     jQuery("#QID464").hide();
    }
  });

});


11 replies

Userlevel 1
Badge +5

or is it possible to at least change the star slider response?

Userlevel 7
Badge +27

In the slider question:

  • Find the elements with the class 'ResultsInput' and set their value to '' (empty)

  • Find the elements with the class 'Filled' and set their width to 0px

Userlevel 1
Badge +5

Thank you TomG
I am new to JQuery and I'm trying to do what you've just said. I have already get the value of the star slider but no luck on changing the value to empty. May I please ask for your help with the code?

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/49022#Comment_49022var slider = jQuery("#"+this.questionId).nextAll(".QuestionOuter").first(); //next question
slider.find(".ResultsInput").val("").trigger("change");
slider.find(".Filled").css("width","0px");

Userlevel 1
Badge +5

TomG I have included the codes as shown below but not sure if it is the right place since it didn't work. The logic is that If I selected "face to face" on the question "The training that you attended took place" then the slider question (competence of the trainers?) should be shown and if I selected "online" then the slider question should hide and reset to empty. Hoping for another help and apologies for bothering you.
Here's the preview link:
https://rochediacx.fra1.qualtrics.com/jfe/preview/previewId/e61cee6e-bee4-487d-bf1e-5ad88e619aee/SV_6X4Qf5JdfHzjwKq?Q_CHL=preview&Q_SurveyVersionID=current
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

var that=this.questionId;

  jQuery("#QID464").hide();

  jQuery("#"+ this.questionId+" input[type='radio']").on('change',function(){ 
    if(jQuery("[id='QR~"+that+"~1']").prop('checked')){
     jQuery("#QID464").show();
     //alert("ResultsInput :"+$$('.ResultsInput')[4].value);
    }else{
     jQuery("#QID464").hide();
var slider = jQuery("#"+this.questionId).nextAll(".QuestionOuter").first(); //next question
slider.find(".ResultsInput").val("");
slider.find(".Filled").css("width","0px");
    }
  });

});

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/49027#Comment_49027Your initial question wasn't clear. It seemed like there was one slider question with three rows, instead of separate sliders questions with a text/graphic question before them. So, the JS I provided to find the next question doesn't apply. Replace:
var slider = jQuery("#"+this.questionId).nextAll(".QuestionOuter").first(); //next question
with:
var slider = jQuery("#QID464);

Userlevel 1
Badge +5

Hi TomG Thank you. It is now working on the survey but data for the star slider is still present when I checked the Data & Analysis even the star slider value was set to empty. Is there anything else that I missed?

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/49054#Comment_49054Are you sure? When I tried it and piped the answer on the next page it was blank.

Userlevel 1
Badge +5

TomG - I'm checking the Data & Analysis part. The response from the star rating (QID464) should be empty since I have selected code 2 (online) in QID475.
image.pngHere's the exact script that I am using
image.png

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/49116#Comment_49116Add .trigger("change") to the line that sets the ResultsInput value. I've added it to the accepted answer above.

Userlevel 1
Badge +5

Thank you so much TomG. It is now working as expected.

Leave a Reply