In one of my surveys I have sliders, where I present above the slider the value on the slider, plus the maximum value of the slider minus the value of the slider itself (i.e. the value of the slider if you were to start from the right side). This is because the slider is serving as an allocation of some fixed amount of money between two individuals.
I was able to implement this with the below:
`Qualtrics.SurveyEngine.addOnReady(function()
{
var s = jQuery("#"+this.questionId);
var result=0;
var otherend=0;
var firstclick=0;
s.find(".handle").hide();
s.find(".track").on("click", function() {
s.find(".handle").show();
firstclick=firstclick+1;
});
jQuery(".Skin").mousemove(function () {
if (firstclick < 1) {
jQuery(".result").html(0);
jQuery(".otherend").html(0);
} else if (firstclick>=1) {
result = jQuery(".ResultsInput").val();
otherend = 100 - result;
jQuery(".result").html(result);
jQuery(".otherend").html(otherend);
};
});
});`
However, I now have a page on my survey where I have multiple of these sliders, so while the code works to show the values of the first slider, it doesn't work for any of the remaining sliders (which all show the values corresponding to the first slider). I've made sure to make all the variable names unique, and tried changing `jQuery(".result").html(result);` to `jQuery("#result").text(result);` using `<span id="otherend"></span>` instead to see what works to get the values to show up right on the page.
Of course, I've realized that the issue is that for each of the 10 sliders (I have each slider on a different question of the corresponding block), I'm pulling in `result = jQuery(".ResultsInput").val();`, which I guess refers only to the value of whichever slider is _first_ on the page. I've been using Inspect to see what I would replace ".ResultsInput" with to get the value of each of the remaining sliders on the page, but nothing has worked (i.e. replacing with something like "#QID5" or "#QID5~1", etc. or using the getChoiceAnswerValue / getChoiceValue methods from the Qualtrics Javascript API instead of .val(). I just need a way to refer to the results from all sliders and not just the first one, and am unable to do so.
Survey Preview link: https://harvard.az1.qualtrics.com/jfe/preview/SV_6nWXIyin3MtK48l?Q_SurveyVersionID=current&Q_CHL=preview
Thanks!
Page 1 / 1
All your jQuery commands in the mousemove handler function need to be specific to the question, such as:
```
result = s.find(".ResultsInput").val();
```
```
result = s.find(".ResultsInput").val();
```
I am trying to use this code, but it correctly displays only for 100 unit (e.g $). I need another amount, do you know how to achieve that?
Thanks.
(just changing the amount in the code does not work, ofc)
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.