I have a survey to which I've added some Javascript: Participants can use an "add button" and a "remove button" to decide how many groups they which to group the list of items into, by adding and removing groups as they wish. You can see how it works here https://samgu.eu.qualtrics.com/jfe/form/SV_czQxglGYSFUQ6zQ
The problem is that when an item has been added to a group, and a participant decides to remove that group, the items that have been added to that group stays in that group, hidden. So, when they hit the "add button" the perviously chosen items appear in that group again. I wish instad that all items that are in a group that is removed are thrown back into the list of items again.
Is it somehow possible to use Javascript to move items in a way that could help me with this problem?
Current html:
How do I move items in Pick, Group, Rank using Javascript?
Current Javascript:
Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("div.Group:not(:first)").hide();
jQuery("#addbutton").on('click',function(){ jQuery("div.Group:eq("+parseInt(parseInt(jQuery("div.Group:visible").length))+")").show();
});
jQuery("#removebutton").on('click',function(){ jQuery("div.Group:eq("+parseInt(parseInt(jQuery("div.Group:visible").length-1))+")").hide();
});
});
Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery("#"+this.questionId+" .rank").hide();
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Thanks in advance!
Best answer by ahmedA
Qualtrics.SurveyEngine.addOnReady(function () {
let quest = this;
let boxes = quest.questionContainer.querySelectorAll(".AnswerContainer"),
add_button = quest.questionContainer.querySelector("#addbutton"),
remove_button = quest.questionContainer.querySelector("#removebutton"),
tracker = 1,
all_choices = quest.getChoices();
boxes.forEach((box) => box.hide());
boxes[tracker - 1].show();
add_button.onclick = function () {
if (tracker < boxes.length) {
tracker++;
boxes[tracker - 1].show();
} else {
alert("Max Boxes");
}
};
remove_button.onclick = function () {
if (tracker <= 1) {
alert("Min Boxes");
return false;
}
let clear_choices = [];
all_choices.forEach((item) => {
if (quest.getChoiceAnswerValue(item) == tracker) clear_choices.push(item);
});
clear_choices.forEach((ch) => {
quest.setChoiceAnswerValue(ch, tracker, 0);
});
tracker--;
boxes[tracker].hide();
};
});
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.
