Hello all,
I'm new to javascript and have been adapting Kurt Munz's method of carrying forward rank order questions:
Updated: Rank-Order Carry Forward in Qualtrics with Javascript - Kurt MunzIt actually works fine. The rank order in question 1 is the item order in the constant sum question 2. The problem is that I then want to feed the constant sum data into a new array, sort the array based on the item descriptor, and then save those values as embedded variables. It is my way of putting the variables back into some kind of order for later data analysis. Otherwise the constant sum data is organized by the order the subject ranked things, rather than some constant order I can feed into a stat program.
Two things aren't working:
1.) it isn't sorting based on the descriptor.
2.) For some reason the new array indexes at [4] rather than [0]. So '${q://QID5/ChoiceNumericEntryValue/1}' is recorded in choice[4][0] rather than choice [0][0] (and so on through the list). Any thoughts on this? The former issue I can probably figure out by googling more on javascript. But I'm deeply confused on the latter. All embedded variables are declared in the survey flow.
Qualtrics.SurveyEngine.addOnload(function()
{ // hide next button
$('NextButton') && $('NextButton').hide();
// store score in first column, description in second column of array "choice"
var choice = [
['${q://QID5/ChoiceNumericEntryValue/1}','${q://QID5/ChoiceDescription/1}'],
['${q://QID5/ChoiceNumericEntryValue/2}','${q://QID5/ChoiceDescription/2}'],
['${q://QID5/ChoiceNumericEntryValue/3}','${q://QID5/ChoiceDescription/3}'],
['${q://QID5/ChoiceNumericEntryValue/4}','${q://QID5/ChoiceDescription/4}'], ['${q://QID5/ChoiceNumericEntryValue/5}','${q://QID5/ChoiceDescription/5}'],
['${q://QID5/ChoiceNumericEntryValue/6}','${q://QID5/ChoiceDescription/6}'],
['${q://QID5/ChoiceNumericEntryValue/7}','${q://QID5/ChoiceDescription/7}'],
['${q://QID5/ChoiceNumericEntryValue/8}','${q://QID5/ChoiceDescription/8}'],
['${q://QID5/ChoiceNumericEntryValue/9}','${q://QID5/ChoiceDescription/9}'],
['${q://QID5/ChoiceNumericEntryValue/10}','${q://QID5/ChoiceDescription/10}'],
['${q://QID5/ChoiceNumericEntryValue/11}','${q://QID5/ChoiceDescription/11}'],
['${q://QID5/ChoiceNumericEntryValue/12}','${q://QID5/ChoiceDescription/12}']
];
// sort choice BY DESCRIPTION
choice.sort(sortFunction);
function sortFunction(a, b) {
if (a[1] === b[1]) {
return 0;
}
else {
return (a[1] < b[1]) ? -1 : 1;
}
}
Qualtrics.SurveyEngine.setEmbeddedData('firstEND',choice[0][0]);
Qualtrics.SurveyEngine.setEmbeddedData('secondEND',choice[1][0]);
Qualtrics.SurveyEngine.setEmbeddedData('thirdEND',choice[2][0]);
Qualtrics.SurveyEngine.setEmbeddedData('fourthEND',choice[3][0]);
Qualtrics.SurveyEngine.setEmbeddedData('fifthEND',choice[4][0]);
Qualtrics.SurveyEngine.setEmbeddedData('sixthEND',choice[5][0]);
Qualtrics.SurveyEngine.setEmbeddedData('seventhEND',choice[6][0]);
Qualtrics.SurveyEngine.setEmbeddedData('eighthEND',choice[7][0]);
Qualtrics.SurveyEngine.setEmbeddedData('ninthEND',choice[8][0]);
Qualtrics.SurveyEngine.setEmbeddedData('tenthEND',choice[9][0]);
Qualtrics.SurveyEngine.setEmbeddedData('eleventhEND',choice[10][0]);
Qualtrics.SurveyEngine.setEmbeddedData('twelfthEND',choice[11][0]);
// advance to next screen
this.clickNextButton();
});
Array not indexed at zero?
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
