Hi,
I was trying to upgrade the code jdiffee provided (https://www.qualtrics.com/community/discussion/1822/how-to-change-the-value-for-the-stars-slider) to make it possible to use the functionality of Star Labels on mobile. As for now, it doesn't respond on touchstart events, but it works good on click.
Unfortunately, as I am very new in JS, I failed.
Could you please help me to make it right? This is one of my last attempts.
Qualtrics.SurveyEngine.addOnload(function()
{
this.addEventListener('click', 'touchstart');
});
Qualtrics.SurveyEngine.addOnReady(function()
{
//set descriptions
var _desc = ['Terrible','Poor','Average','Good','Excellent'];
//hide default results
jQuery("[id$='~result']").hide();
//click handler
this.questionclick = function(event,element)
{
//get selected choices
var _choices = this.getSelectedChoices();
//loop through selected choices
for (var i in _choices) {
var _prefix = (this.questionId + "~" + _choices[i]), //build element id
_result = jQuery("[id='" + _prefix + "~result" + "']"), //get element obj
_val = parseInt(_result.val()); //get element value
//remove old description element
jQuery("[id='" + _prefix + "~desc" + "']").remove();
//add new description element
_result.after("" + _desc[_val-1] + "");
}
}
});
Solved
Stars Labels on mobile
Best answer by Tom_1842
var qid = this.questionId;
var question = document.getElementById('Questions');
var width1 = document.getElementById(qid+'~x1~result');
var right1 = document.getElementById(qid+'~x1~RightBorder');
var width2 = document.getElementById(qid+'~x2~result');
var right2 = document.getElementById(qid+'~x2~RightBorder');
var width3 = document.getElementById(qid+'~x3~result');
var right3 = document.getElementById(qid+'~x3~RightBorder');
var width4 = document.getElementById(qid+'~x4~result');
var right4 = document.getElementById(qid+'~x4~RightBorder');
var width5 = document.getElementById(qid+'~x5~result');
var right5 = document.getElementById(qid+'~x5~RightBorder');
jQuery(question).on("click , touchstart", function() {
//Statement1//
var widthval1 = parseInt(jQuery(width1).val());
if(widthval1==1){
jQuery(right1).text("Terrible").css({"font-size":"14px"});
}
if(widthval1==2){
jQuery(right1).text("Poor").css({"font-size":"14px"});
}
if(widthval1==3){
jQuery(right1).text("Average").css({"font-size":"14px"});
}
if(widthval1==4){
jQuery(right1).text("Good").css({"font-size":"14px"});
}
if(widthval1==5){
jQuery(right1).text("Excellent").css({"font-size":"14px"});
}
//Statement2//
var widthval2 = parseInt(jQuery(width2).val());
if(widthval2==1){
jQuery(right2).text("Terrible").css({"font-size":"14px"});
}
if(widthval2==2){
jQuery(right2).text("Poor").css({"font-size":"14px"});
}
if(widthval2==3){
jQuery(right2).text("Average").css({"font-size":"14px"});
}
if(widthval2==4){
jQuery(right2).text("Good").css({"font-size":"14px"});
}
if(widthval2==5){
jQuery(right2).text("Excellent").css({"font-size":"14px"});
}
//Statement3//
var widthval3 = parseInt(jQuery(width3).val());
if(widthval3==1){
jQuery(right3).text("Terrible").css({"font-size":"14px"});
}
if(widthval3==2){
jQuery(right3).text("Poor").css({"font-size":"14px"});
}
if(widthval3==3){
jQuery(right3).text("Average").css({"font-size":"14px"});
}
if(widthval3==4){
jQuery(right3).text("Good").css({"font-size":"14px"});
}
if(widthval3==5){
jQuery(right3).text("Excellent").css({"font-size":"14px"});
}
//Statement4//
var widthval4 = parseInt(jQuery(width4).val());
if(widthval4==1){
jQuery(right4).text("Terrible").css({"font-size":"14px"});
}
if(widthval4==2){
jQuery(right4).text("Poor").css({"font-size":"14px"});
}
if(widthval4==3){
jQuery(right4).text("Average").css({"font-size":"14px"});
}
if(widthval4==4){
jQuery(right4).text("Good").css({"font-size":"14px"});
}
if(widthval4==5){
jQuery(right4).text("Excellent").css({"font-size":"14px"});
}
//Statement5//
var widthval5 = parseInt(jQuery(width5).val());
if(widthval5==1){
jQuery(right5).text("Terrible").css({"font-size":"14px"});
}
if(widthval5==2){
jQuery(right5).text("Poor").css({"font-size":"14px"});
}
if(widthval5==3){
jQuery(right5).text("Average").css({"font-size":"14px"});
}
if(widthval5==4){
jQuery(right5).text("Good").css({"font-size":"14px"});
}
if(widthval5==5){
jQuery(right5).text("Excellent").css({"font-size":"14px"});
}
})
And because the formatting from the first post was lost, below is the CSS:
.Skin .STAR .horizontalbar table.sliderGrid tr td.value {
max-width: 1px !important;
min-width: 1px !important;
}
.Skin .horizontalbar .RightBorder {
min-width: 60px;
}
.Skin .horizontalbar table.sliderGrid tr td.value input, .Skin .horizontalbar tr.Stars td.value input {
display: none;
}
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.