Multiple star sliders- how to set custom values | XM Community
Solved

Multiple star sliders- how to set custom values

  • 20 September 2019
  • 7 replies
  • 29 views

Userlevel 1
Hi all,

I have this question and I found this code to have different values show to the respondent (ATTACHMENT)
!

The problem is that the code only works for a single star slider.
Can anyone please provide me with a code for multiple star sliders?

Thanks so much
icon

Best answer by KimothiSaurabh 23 September 2019, 12:48

View original

7 replies

Userlevel 4
Badge +18
@BettoLamacchia - I have tweaked your code slightly to work with multiple star slider, please have a look:-

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery('.ResultsInput').hide();
jQuery('.ResultsInput').after("<span id='autoinsert'></span>");
jQuery('.ResultsInput').on("change input",function()
{
console.log('aa');
var widthvalue = parseInt(jQuery(this).val());
if (widthvalue==1)
{
jQuery(this).next().html("Molto insoddisfatto");
}
if (widthvalue==2)
{
jQuery(this).next().html("Insoddisfatto");
}
if (widthvalue==3)
{
jQuery(this).next().html("Molto 3");
}
if (widthvalue==4)
{
jQuery(this).next().html("Molto 4");
}
if (widthvalue==5)
{
jQuery(this).next().html("Molto 5");
}
});

});
Userlevel 1
Hi @KimothiSaurabh, many thanks, it works!
As I want to have this question mobile friendly, have you got a code have values show above each star slider instead of the right side?

Thanks again
Userlevel 4
Badge +18
@BettoLamacchia - That setup is mobile friendly by default bu if you still want values to be shown above starts, you can use this code:-

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery('.ResultsInput').hide();
jQuery('tbody .BarOuter').prepend("<div class='autoinsert'></div>")
jQuery('.ResultsInput').on("change input",function()
{
var widthvalue = parseInt(jQuery(this).val());
if (widthvalue==1)
{
jQuery(this).parent().parent().find('.autoinsert').html("Molto insoddisfatto");
}
if (widthvalue==2)
{
jQuery(this).parent().parent().find('.autoinsert').html("Insoddisfatto");
}
if (widthvalue==3)
{
jQuery(this).parent().parent().find('.autoinsert').html("Molto 3");
}
if (widthvalue==4)
{
jQuery(this).parent().parent().find('.autoinsert').html("Molto 4");
}
if (widthvalue==5)
{
jQuery(this).parent().parent().find('.autoinsert').html("Molto 5");
}
});

});
Userlevel 1
> @KimothiSaurabh said:
> @BettoLamacchia - That setup is mobile friendly by default bu if you still want values to be shown above starts, you can use this code:-
>
> Qualtrics.SurveyEngine.addOnReady(function()
> {
> /*Place your JavaScript here to run when the page is fully displayed*/
> jQuery('.ResultsInput').hide();
> jQuery('tbody .BarOuter').prepend("<div class='autoinsert'></div>")
> jQuery('.ResultsInput').on("change input",function()
> {
> var widthvalue = parseInt(jQuery(this).val());
> if (widthvalue==1)
> {
> jQuery(this).parent().parent().find('.autoinsert').html("Molto insoddisfatto");
> }
> if (widthvalue==2)
> {
> jQuery(this).parent().parent().find('.autoinsert').html("Insoddisfatto");
> }
> if (widthvalue==3)
> {
> jQuery(this).parent().parent().find('.autoinsert').html("Molto 3");
> }
> if (widthvalue==4)
> {
> jQuery(this).parent().parent().find('.autoinsert').html("Molto 4");
> }
> if (widthvalue==5)
> {
> jQuery(this).parent().parent().find('.autoinsert').html("Molto 5");
> }
> });
>
> });

Many thanks, that's great 🙂
Badge +1
Hi! Do you know how to have the custom values localized if there's translations in the survey?
Userlevel 4
Badge +18
You can create a span and fetch text from there. Put this span in you questions text So it would be like:-

<span class='rate5' style="display:none;">Molto 5</span>

jQuery(this).parent().parent().find('.autoinsert').html(jQuery('.rate5').html());
Badge +1
Thank you @KimothiSaurabh !

Leave a Reply