0

In Qualtrics, I am trying to get the slider value of the response when the next button is clicked using javascript. I have tried many proposed solutions including everything in this question. But none of them worked.

Update: I also tried the following, did not work:

Qualtrics.SurveyEngine.addOnload(function()
{
var q = this.getQuestionInfo();

$('NextButton').onclick =function(event,element)
{
    alert("${q://1_QID1/ChoiceNumericEntryValue/1}");
    alert(this. questionId+","+q.QuestionID);
    var p = "q://"+q.QuestionID+"/ChoiceNumericEntryValue/1";
    var v = "${p}";

    alert(v);
}

});
Rakib
  • 7,435
  • 7
  • 29
  • 45
  • Can you post the dom structure? – karthick Feb 16 '18 at 00:47
  • The answer will be different depending on whether you have the Mobile Friendly checked. There are two different structures - Mobile Friendly under JFE and everything else. Which are you working with? Also, you'll want to use a setInterval to get the value rather than trying to tie it to the Next Button. – T. Gibbons Feb 16 '18 at 15:04
  • @T.Gibbons, it does not have Mobile Friendly checked. If I can store the value in some embedded field and later retrieve when next button is clicked that will also be helpful. – Rakib Feb 16 '18 at 15:09
  • Is there just one slider or multiple? – T. Gibbons Feb 16 '18 at 15:34
  • @T.Gibbons, only one slider, and only one question in the block. But the block has loop and merge and the question is repeated multiple times. – Rakib Feb 16 '18 at 17:34
  • Sorry, one more question. I was thinking too much about the JS and not about your actual need. If all you want is the value of the slider after the Next button is clicked, why not just pipe it where you need it? (e.g., ${q://1_QID1/ChoiceNumericEntryValue/1} – T. Gibbons Feb 16 '18 at 17:54
  • @T.Gibbons, can you please post an answer with 2-3 lines of working code? Do I have to replace the 1_QID1 with actual question id? – Rakib Feb 16 '18 at 18:50

2 Answers2

0

Since you don't need the slider value until after the Next Button is clicked, you don't need any JavaScript. You can just pipe the answer where you need it (another question, the survey flow, a JavaScript, etc.). To get the piped string, just click on the question text to any question, then select Piped Text/Survey Question/the question/the loop/the choice. The pipe string will look like ${q://1_QID1/ChoiceNumericEntryValue/1} where 1_ is the loop number, QID1 is the question id, and /1 is the choice.

T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
  • Thanks for your answer. Actually I need the value before moving to the next question. Second issue is the loop will repeat for 30 times, but I will need the value for 3 times which are randomized using another javascript function, depending on some embedded data and loop counter. Hence using javascript seemed most flexible. – Rakib Feb 16 '18 at 22:10
  • I just tried this method, while I can get the question text using 'questionText', the value of the slider returns empty when I use 'ChoiceNumericEntryValue'. – Rakib Feb 16 '18 at 22:19
0

I know this is very late but I was searching the same question, and through a bit of digging of my own through someone else's survey, found the following snippet that worked, copying it into the text of the question in HTML View (where you replace QID29 with whatever QIDxx your question is) (the 'value=""' is such that the textbox where the slider value is displayed is empty before the respondent moves the handle on the slider; it can be made to value="x" where x is whatever you'd like, i.e. the default on the slider, for example):

<input class="SumInput InputText QID29 QWatchTimer" data-runtime- value="runtime.Choices.1.Value" id="QID29" name="QID29" type="text" value="">
RRTG
  • 35
  • 8