jquery - How to format Qualtrics embedded data on a per-input basis? -
what i'm trying accomplish grab embedded data, , output in specific way (color, position, etc.). instance, put embedded data <div class="previous">$e://field/dtbeg}</div>
in question text, want grab , insert directly under input field (something don't think can directly in qualtrics, custom js needed here).
so in question text, have:
<div>1a. reporting period: beginning</div> <div class="previous date">${e://field/dtbeg}</div>
where dtbeg
data may empty, or may 5/6 digits representing date. header of survey has:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> var $j = jquery.noconflict(); </script>
as explained in documentation.
so in jquery can access field's previous data $j(".previous")
, issue qualtrics puts 2 (or more, depending on question type) <div class="previous date"></div>
fields in question. misleading now, because each embedded data may have additional "previous" divs, there's no way me determine if embedded data empty, or if duplicate field.
... <h2 class="nostyle"> <label class="questiontext bordercolor"> <div>1b. reporting period: end</div> <div class="previous date">33113</div> <!-- first instance of div, seems visible --> </label> </h2> <fieldset> <div class="questionbody"> <table class="choicestructure" border="0" cellpadding="0" cellspacing="0" summary=" 1b.&nbsp; reporting period:&nbsp; end&nbsp; 33113 " style="width:710px"> <caption class="questiontext bordercolor"> <div>1b. reporting period: end</div> <div class="previous date">33113</div> <!-- second instance of div, seems hidden --> </caption> ... </div> </fieldset ...
is there better way accomplish i'm trying do? i'm fine writing own js so, far, because qualtrics' html output isn't quite expected i'm running issues.
try following javascript in necessary question:
qualtrics.surveyengine.addonload(function() { $$('.questionbody')[0].insert($$('.previous')[0]); });
rather using jquery , having go hassle, uses baked in prototypejs. selector
$$('.class')
will return array of elements. since there , should 1 element "previous" class, first , element in array. number selected ".questionbody" array need adjusted based on number of questions on page, , showing.
also worth noting
$('idname')
can used select element id, , not return array.
Comments
Post a Comment