javascript - Qualtrics Table Conditional Formatting -


in qualtrics survey, 1 question (descriptive text) two-column table populated randomly-chosen embedded data 2 different countries (the v2elsuffrage_ord variables below). both of these variables numbers 0-4. want conditionally format these cells, whichever score bigger (score1 or score2), cell green.

here's example of table:

<table class="usertable">     <colgroup>         <col id="score1" />         <col id="score2" />     </colgroup>     <tbody>         <tr>             <th>country a</th>             <th>country b</th>         </tr>         <tr>             <td>${e://field/v2elsuffrage_ord}</td>             <td>${e://field/v2elsuffrage2_ord}</td>         </tr>     </tbody> </table> 

is possible in qualtrics? found example of normal conditional formatting in html , tried modify qualtrics, didn't work. did javascript:

qualtrics.surveyengine.addonload(function() {      var score1 = $(this).text();     var score2 = $(this).text();      if (score1 > score2) {         $(this).addclass('more1');     }     else if (score1 < score2) {         $(this).addclass('more2');     }     else if (score1 = score2) {         $(this).addclass('same');     } }); 

then css, added code under advanced section of & feel (colors randomly chosen right see if work):

.more1 {     background-color: #0f0; }  .more2 {     background-color: #0c0; }  .same {     background-color: #060; } 

i know i'm doing incorrectly, i've never worked in html/css (and said, don't know if possible). ideas or guidance great, if it's workaround.

there bunch of errors in javascript:

  1. $(this) wrong
  2. text() jquery function, not prototypejs or native javascript function
  3. score1 = score2 invalid comparison
  4. addclass isn't valid function

also, style assignment logic , css doesn't make sense. need 1 style. since case, it's simpler add style element. no need separate css.

try javascript instead...

qualtrics.surveyengine.addonload(function() {  var score1 = parseint("${e://field/v2elsuffrage_ord}"); var score2 = parseint("${e://field/v2elsuffrage2_ord}");  if (score1 > score2) {     $('score1').style.backgroundcolor = "#0f0"; } else if (score1 < score2) {     $('score2').style.backgroundcolor = "#0f0"; } }); 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -