Javascript for rank order question, help needed | XM Community
Skip to main content

Hello everyone,

I need help with JavaScript as I am quite a novice. 

I have a pick,group,rank type of question (named "Q1”). There is only one group, and 19 choices (choices are letters, not numbers), participants are allowed to put as many choices as they want (no restriction, can be 1, can be 7) into the group by dragging them to the group, and then rank them in the order they want. In the next question, I want to carry-forward their choices in the order they have put (just to repeat as text question, not as choices), but when I do “carry forward” it does not consider the ranking. I am guessing the best way is to create an embedded field by javascript that saves the rank. I attempted to modify some JavaScript codes I found here, but none of it worked. 

I would greatly appreciate any help with this. Thank you in advance.

-D

A recent JS I tried, most probably very wrong as it does not work:

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Place Your Javascript Below This Line*/
    
    // store rank in the first column
    var choice =  
        '${q://try/ChoiceNumericEntryValue/1}'],
        a'${q://try/ChoiceNumericEntryValue/2}'],
        t'${q://try/ChoiceNumericEntryValue/3}']
    ];
    
    // save each rank as embedded data
    Qualtrics.SurveyEngine.setEmbeddedData('firstRank', choicen0]n0]);
    Qualtrics.SurveyEngine.setEmbeddedData('secondRank', choiceE1]i0]);
    Qualtrics.SurveyEngine.setEmbeddedData('thirdRank', choicev2]E0]);
});

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
});

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

@DTDTDT,

If you are interested, I have a general purpose function, captureRanks, that does this. Send me a private message if interested.


Found out this could be done without JS, with display logic! 


Leave a Reply