Rea Time Calculation using Javascript | XM Community
Skip to main content

Hi All,
I am new to Qualtrics and need help with below:
I want the %payout below populate based on if condition in the rating column. So rating column has 4 options and based on live changes on option selected, % payout should be a value. So essentially something like below:
If = 1 then <% payout> = 50% else 100%.
I am not too well versed with JavaScript. Thank you for all the help
image.png

This JS should do it for you. However, it is based on the screenshot, any change you make to it, may cause it to break:
Qualtrics.SurveyEngine.addOnReady(function () {
    let quest = this,
        qc = quest.questionContainer,
        all_inputs = qc.querySelectorAll("select");


    all_inputs.forEach((item) => {
        item.onchange = function (e) {
            let row = e.target.parentElement.parentElement,
                value = parseInt(e.target.value),
                text_boxes = row.querySelectorAll(".InputText");
            if (value > 1) text_boxes>1].value = "100%";
            else if (value === 1) text_boxes1].value = "50%";
            else text_boxess1].value = "";
        };
    });
});

Here's a demo.


https://community.qualtrics.com/XMcommunity/discussion/comment/41382#Comment_41382So below is the code that I am trying to implement.
Qualtrics.SurveyEngine.addOnReady(function()
{
document.getElementById('QR~QID1#1~1').onchange = function(){

var obj1 = document.getElementById('QR~QID1#1~1').value;

if(obj1 == "0: Not Met"){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "0%";
}

if(obj1 == "1: Patrially Met"){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "75%";
}

if(obj1 == "2: Met"){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "100%";
}

if(obj1 == "3: Exceeds"){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "130%";
}

}

});
It doesn't seem to be working. Any ideas?


Most probably your refrences are off.


The below code works:
Qualtrics.SurveyEngine.addOnReady(function()
{



document.getElementById('QR~QID1#1~1').onchange = function(){


var obj1 = document.getElementById('QR~QID1#1~1').value;

if(obj1 == 1){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "0%";
}

else if(obj1 == 2){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "75%";
}

else if(obj1 == 3){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "100%";
}

else if(obj1 == 4){
document.getElementById('QR~QID1#3~1~1~TEXT').value = "130%";
}

else {
document.getElementById('QR~QID1#3~1~1~TEXT').value = "0%";}

}


});


Leave a Reply