Skip to content

Commit

Permalink
few functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tafakkur committed Dec 9, 2020
1 parent dad2ec7 commit e1f0349
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions JavaScript Files/Constant Sum Allow only integers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Qualtrics.SurveyEngine.addOnReady(function () {
//Get the Question Id
const qid = this.questionId;
// Get the number of choices
n_choices = Qualtrics.SurveyEngine.registry[qid].getChoices();

const base_msg = jQuery("#" + qid + " .QuestionText").html();
padding_pre = '<br> <a style="color:red;">';
padding_post = "</a>";
err_msg = base_msg + padding_pre + "Please enter only valid integer numbers." + padding_post;

// Detect a change in any of the choices
n_choices.forEach((item) => {
document.querySelector("#QR\\~" + qid + "\\~" + item).oninput = function () {
if (document.querySelector("#QR\\~" + qid + "\\~" + item).value.search(/\D/) != -1) {
jQuery("#" + qid + " .QuestionText").html(err_msg);
} else {
jQuery("#" + qid + " .QuestionText").html(base_msg);
}
};
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
const qid = this.questionId;
available_choices = Qualtrics.SurveyEngine.QuestionInfo[qid].Choices;

tot_choices = []
for(keys in available_choices){
tot_choices.push(keys);}

choice_set ={};
i=1;
tot_choices.forEach(item =>{
option_score = document.getElementsByName("QR~"+qid+"~"+item)[0].value;
option_name = document.getElementById("header~"+qid+"~"+i).innerText.trim();
choice_set[option_name] = option_score;
i++;
});

const sorted_choices = Object.fromEntries(
Object.entries(choice_set).sort(([,a],[,b]) => b-a)
);

i = 1;
for(keys in sorted_choices){
Qualtrics.SurveyEngine.setEmbeddedData("top_"+i, keys);
i++;
}
});

0 comments on commit e1f0349

Please sign in to comment.