In the NPS element a code was made to have all the numbers before the previous numbers highlighted. What is needed as well is for them to have the blue border as well.
in the image ,4 is selected. All numbers before 4 are highlighted, but I am not being able to assign borders to them as well
What can I do to have the numbers before the selected number have highlighted borders as well.
code used:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery(".SingleAnswer").click(function() {
for (var i=0;i<=10;i++){
jQuery("td:eq(" + i +")").find('label').css("background-color", "rgba(0,0,0,.06)");
jQuery("td:eq(" + i +")").find('label span').css("color", "#888b8d");
}
var selected = jQuery(this).text();
for (var i=0;i<=selected;i++){
jQuery("td:eq(" + i +")").find('label').css("background-color", "#f6f6f6");
jQuery("td:eq(" + i +")").find('label span').css("color", "#002B7C");
jQuery("#" + this.questionId + " td.LabelContainer.LabelContatiner.reg ").css( " border-style ", "solid ");
jQuery("#" + this.questionId + " td.LabelContainer.LabelContatiner.reg ").css( " border-width ", "2px ");
jQuery("#" + this.questionId + " td.LabelContainer.LabelContatiner.reg ").css( " border-color ", "#002B7C ");
/* ( this is what I tried to use for enabling the border color)
jQuery("td:eq(" + i +")").find(' .Skin label.SingleAnswer ').css(" border-style ", "solid ");
jQuery("td:eq(" + i +")").find(' .Skin label.SingleAnswer ').css(" border-width ", "2px ");
jQuery("td:eq(" + i +")").find(' .Skin label.SingleAnswer ').css(" border-color ", "#002B7C ");
*/
}
jQuery("td:eq(" + i +")").find('label span').css("color", "#002B7C");
jQuery("#" + this.questionId + " .SingleAnswer ").css( " border-style ", "solid ");
jQuery("#" + this.questionId + " .SingleAnswer ").css( " border-width ", "2px ");
jQuery("#" + this.questionId + " .SingleAnswer").css( " border-color ", "#002B7C ");
jQuery("#" + this.questionId + " .SingleAnswer").css( " background-color ", "#002B7C ");
})
( this is the end of the code that I used, but non of the elements are being affected)
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Hi there, I played around with your code a bit and below is the closes I was able to get it. First, I added some CSS to reduce the space between answer options. This makes it so that there is 1 large border around the choices to the left, even though a border is being added to the choices individually.
.Skin .MC .ChoiceStructure {
border-spacing: 0px !important;
}
Next, add the below JavaScript to the Onload portion of your NPS question:
var qid = this.questionId;
var leftpoint = document.getElementById(qid+'-0-label');
jQuery(".SingleAnswer").click(function() {
//Sets styles for all answers on answer selection//
for (var i=0;i<=11;i++){
jQuery("td:eq(" + i +")").find('label').css("background-color", "rgba(0,0,0,.06)");
jQuery("td:eq(" + i +")").find('label span').css("color", "#0000ff");
jQuery("td:eq(" + i +")").find('label').css("border-bottom-style", "none");
jQuery("td:eq(" + i +")").find('label').css("border-top-style", "none");
}
//Sets styles for answers to the left of the selection on answer selection//
var selected = jQuery(this).text();
for (var i=0;i<=selected;i++){
jQuery("td:eq(" + i +")").find('label').css("background-color", "rgba(255,255,255,.06)");
jQuery("td:eq(" + i +")").find('label span').css("color", "#ff0000");
jQuery("td:eq(" + i +")").find('label').css("border-bottom-style", "solid");
jQuery("td:eq(" + i +")").find('label').css("border-top-style", "solid");
jQuery("td:eq(" + i +")").find('label').css("border-top-color", "#0000FF");
jQuery("td:eq(" + i +")").find('label').css("border-bottom-color", "#0000FF");
}
//Sets left border for left choice on answer selection//
leftpoint.style.borderLeft = "solid #0000FF";
})
Tom_1842 , I added these 2 lines of code to your code
jQuery("td:eq(" + i +")").find('label').css("border-left-style", "solid");
jQuery("td:eq(" + i +")").find('label').css("border-right-style", "solid");
jQuery("td:eq(" + i +")").find('label').css("border-left-color", "#0000FF");
jQuery("td:eq(" + i +")").find('label').css("border-right-color", "#0000FF");
And I was able to get the desired outcome.
I want to thank you so much for your time and effort!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.