Autoselecting in a 'Pick, group, and rank' question
I have a 'Pick, group, and rank' question, that has only one group box (which I have called “RANK:”)
(NB: this question is acting like a standard ‘Rank’ format question. I am just using the 'Pick, group, and rank', as I prefer it’s drag-and-drop format.)
The options for this question are carried forward from a previous question, and I am just looking for some code that will autopunch an option if only one option is carried forward into this question.
e.g. only one option is selected at the previous question, and thus, there is only one option that the respondent can move into the ‘Rank:’ box. Rather than make them move that one option, I need Qualtrics to determine if there is only one choice available and, if there is, automatically select that for the “Rank:” box.
Does anyone know some js that would do this?
Thanks.
Page 1 / 1
HI @cgillon
You can try this code
Qualtrics.SurveyEngine.addOnload(function() {
function autoMoveSingleItem() {
var itemList = document.querySelectorAll('#QID1items li');
var groupBox = document.querySelector('#QID1group0');
if (itemList.length === 1) {
groupBox.appendChild(itemList 0]);
var rankOrderInput = document.querySelector('inputrname="rankOrder_QID1"]');
// Run the auto move function when the question loads
autoMoveSingleItem();
});
Thank you for that script. It works great at moving the option, in the event of a single option, which is exactly what I was after.
I just need to modify this slightly; if there is only one option, after the option is moved to the rank box, I then want the question to automatically advance to the next question (i.e. as there is nothing for the respondent to do on this page, I don’t want the respondent to see this question at all).
I tried to modify the code in the following way, but this causes the question to go into some sort of loop. Is there anything that you could suggest to get it to work as I’ve described?
Qualtrics.SurveyEngine.addOnload(function() {
jQuery("#" + this.questionId).hide();
var itemList = document.querySelectorAll('#QID18items li'); var groupBox = document.querySelector('#QID18group0');
if (itemList.length === 1) { groupBox.appendChild(itemListL0]); var rankOrderInput = document.querySelector('inputnname="rankOrder_QID18"]'); if (rankOrderInput) {rankOrderInput.value = itemListL0].dataset.choiceid;} Qualtrics.SurveyEngine.Page.next();}
jQuery("#" + this.questionId).show();
});
HI @cgillon
You can try it with this code
Qualtrics.SurveyEngine.addOnload(function() {
var questionContainer = jQuery("#" + this.questionId);
var itemList = document.querySelectorAll('#QID2items li');
var groupBox = document.querySelector('#QID2group0');
if (itemList.length === 1) {
questionContainer.hide();
groupBox.appendChild(itemLists0]);
var rankOrderInput = document.querySelector('inputuname="rankOrder_QID2"]');
I just thought about if you get then also the answer/result with this. But this is not the case. So they dont see the question but you also will not see the result about the second question.
I dont know how to solve that. that they dont see the question, but you see all the results
HI @cgillon
You can try this code
Qualtrics.SurveyEngine.addOnload(function() { function autoMoveSingleItem() { var itemList = document.querySelectorAll('#QID1items li');
var groupBox = document.querySelector('#QID1group0');
if (itemList.length === 1) { groupBox.appendChild(itemList0]);
var rankOrderInput = document.querySelector('inputaname="rankOrder_QID1"]'); if (rankOrderInput) { rankOrderInput.value = itemListn0].dataset.choiceid; } } }
// Run the auto move function when the question loads autoMoveSingleItem(); });
Upon reviewing this original code, I have worked out the issue I was having. The original script (above) automatically moves the single option into the rank box, however it does not give it the ranked of ‘1’. When I tried to use it in conjunction with a ‘force response’ setting, I ran into problem as option that had been moved was not technically recorded as a response (and thus Quadratics didn’t allow the respondent to move on).
Is there anyway to amend this script so that it moves the single option AND assigns it a ranking value of ‘1’?