daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var choicesObject = this.getQuestionInfo().Choices;
  2.    //choices is the array of choiceids
  3.    var choices = Object.keys(choicesObject);
  4.    var Qno = choices.length;
  5.    var test = ['this', 'is', 'rad'];
  6.  
  7.    for (var x = 0; x < Qno; x++) {
  8.      var id = choices[x];
  9.      //var y = id + 1;
  10.      var qid = "QID12-" + id + "-label";
  11.      document.getElementById(qid).innerHTML = test[x];
  12.    }
  13. // This works
  14.    
  15. // hide next button
  16.       $('NextButton') && $('NextButton').hide();
  17.  
  18.       // store rank in first column, description in second column of array "choice"
  19.  
  20.       // le was saved as embedded data from Rank question to inform the current code how many choices to loop through
  21.  
  22.       var le = '${e://Field/gp1length}';
  23.       var len = parseInt(le);
  24.  
  25.       var choiceArray = [];
  26.  
  27.       // create blank 2D array containing descriptions and rank orders
  28.       for (var x = 0; x < len; x++) {
  29.         choiceArray[x] = [];
  30.         for (var y = 0; y < 2; y++) {
  31.           choiceArray[x][y] = 0;
  32.         }
  33.       }
  34.  
  35.       // this does not work, the array contains NaNs
  36.       for (var x = 0; x < len; x++) {
  37.         var y = x + 1;
  38.         var rank = "${q://QID11/ChoiceNumericEntryValue/x" + y + "}";
  39.         var desc = "${q://QID11/ChoiceDescription/x" + y + "}";
  40.         choiceArray[x][0] = parseInt(rank);
  41.         choiceArray[x][1] = desc;
  42.       }
  43.  
  44.       // attempt to sort array by rank order column
  45.       choiceArray = choiceArray.sort(function(a, b) {
  46.         return a[0] - b[0];
  47.       });
  48.  
  49.       for (var x = 0; x < len; x++) {
  50.         var y = x + 1;
  51.         var name = "gp1r" + y;
  52.         Qualtrics.SurveyEngine.setEmbeddedData(name, choiceArray[x][1]);
  53.       }
  54.  
  55.       // advance to next screen
  56.       this.clickNextButton();
  57.    
  58. Qualtrics.SurveyEngine.addOnload(function() {
  59.     var ranks = [
  60.         {"choice":"xx1", "rank": parseInt("${q://QID68/ChoiceNumericEntryValue/x1}")},
  61.         {"choice":"xx2", "rank": parseInt("${q://QID68/ChoiceNumericEntryValue/x2}")},
  62.         {"choice":"xx3", "rank": parseInt("${q://QID68/ChoiceNumericEntryValue/x3}")},
  63.         {"choice":"xx4", "rank": parseInt("${q://QID68/ChoiceNumericEntryValue/x4}")},
  64.         {"choice":"xx5", "rank": parseInt("${q://QID68/ChoiceNumericEntryValue/x5}")},
  65.     ];
  66.     var tbody = jQuery("#"+this.questionId+" div.ChoiceStructure > table.sliderGrid > tbody"); //slider container
  67.     jQuery.each(ranks, function(index) { if(isNaN(this["rank"])) ranks.splice(index, 1); }); //remove NaNs
  68.     ranks.sort(function(a,b) { return a.rank - b.rank; });  //sort by rank
  69.     jQuery.each(ranks, function() {
  70.         tbody.append(tbody.find("tr[choiceid="+this["choice"]+"]")); //order sliders
  71.     });
  72. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top