Add Comma to Slider Label | XM Community
Skip to main content
Solved

Add Comma to Slider Label

  • January 30, 2019
  • 5 replies
  • 104 views

Hi everyone, I have a slider with labels on top indicating dollar values. How do I add a comma to separate each 000? The label current look like "1000" - how do I turn that into "1,000"?

Best answer by Anonymous

Hello @1ag0 , Paste the below code in the js(OnReady) of the question: var s=["$0","$2,000","$4,000","$6,000","$8,000"]; for(var i=0;i<s.length;i++){ jQuery(".TickContainer span:eq("+i+")").html(s[i]); }
View original

5 replies

  • 0 replies
  • Answer
  • March 19, 2019
Hello @1ag0 , Paste the below code in the js(OnReady) of the question: var s=["$0","$2,000","$4,000","$6,000","$8,000"]; for(var i=0;i<s.length;i++){ jQuery(".TickContainer span:eq("+i+")").html(s[i]); }

Forum|alt.badge.img+1
  • 2 replies
  • December 7, 2021

Has anyone found a solution to add a "," to the slider options? Trying to show slider options as "$0", "$100,000", "$200,000", "$300,000, "$400,000", "$500,000". Thanks for any help!


Forum|alt.badge.img

I pasted the JavaScript into the right place and there is no change to the slider. Did I miss something? 

 

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{
var s=["$0","$1,000,000","$2,000,000","$3,000,000","$4,000,000","$5,000,000","$6,000,000","$7,000,000","$8,000,000","$9,000,000","$10,000,000"];
for(var i=0;i<s.length;i++){
jQuery(".TickContainer span:eq("+i+")").html(s[i]);
}

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/

});


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • August 21, 2024

@VicSchiller,

The code only applies to constant sum sliders, not slider questions.

You might be interested in the sliderNumFormat function. If so, contact me by private message.


Forum|alt.badge.img

See below for the code that works… 

 


Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{

    
var $this = jQuery(this.questionContainer);
var s = [
"$0","$1,000,000","$2,000,000","$3,000,000","$4,000,000","$5,000,000",
"$6,000,000","$7,000,000","$8,000,000","$9,000,000","$10,000,000"
];

for (var i = 0; i < s.length; i++) {
jQuery(".QuestionBody .labels-container .numbers li:eq(" + i + ")", $this).html('&nbsp;&nbsp;' + s[i] + '&nbsp;');
}

let mo = new MutationObserver(function() {
let val = jQuery(".sliderToolTip .sliderToolTipBox", $this).text();
if (!val || val.indexOf('$') != -1) {
return;
}
val = '$' + new Intl.NumberFormat('en-US', { maximumSignificantDigits: 3 }).format(val);
jQuery(".QuestionBody .sliderToolTip .sliderToolTipBox", $this).text(val);
});
mo.observe(jQuery(".QuestionBody .sliderToolTip", $this)[0], { attributes: true, attributeFilter: ['style'] });
});
    
    

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/

});

----------------------------------------


Leave a Reply