Hi,
does anyone from the community, know how to make the rank order question in the text box format, automatically rank when the user clicks on the text box?
This code bellow in js, I used it for many years, and now I don't know why, it stopped working
Thank you very much
Qualtrics.SurveyEngine.addOnload(function()
{
var maxRank = 3;
var currentRank = 1;
$$('#'+this.questionId+' .QuestionBody input').each(function(el) {$(el).observe('click', function(event) {
if(currentRank > maxRank)
currentRank = xx ;
event.toElement.value = currentRank++;
})});
var questionID = this.questionId;
$('resetButton').observe('click', function(event) {currentRank = 1; console.log($$('#'+questionID+' .QuestionBody input'));$$('#'+questionID+' .QuestionBody input').each(function(el) {el.value = ""});});
});
rank order text box
Best answer by JeremyK
Alright, just figured it out!
I created a resetButton in my question HTML and tested the textbox reset as well. The only thing I don't like about my solution is I couldn't figure out how to select the elements using the QuestionId, so I omitted it, but that could cause problems in the future (or maybe now) since the jQuery runs against the entire page. Let me know if you have problems with it, thanks!
Here's my take on a solution:
Qualtrics.SurveyEngine.addOnload(function () {
var maxRank = 4;
var currentRank = 1;
jQuery('.ChoiceStructure').children().on("click", function () {
if (currentRank <= maxRank) {
jQuery(this).children("input[type='text']:first").val(currentRank);
currentRank = ++currentRank;
};
});
jQuery('#resetButton').on("click", function () {
jQuery(".ChoiceStructure[role='list']").children().children("input[type='text']").val("");
currentRank = 1;
});
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.