javascript - Prematurely exiting a Loop and Merge block in Qualtrics -
i'm working on qualtrics survey in respondents have solve long list of anagrams, , answer demographic questions.
to make anagram part easier, i've used loop , merge block: first field anagram solved, second field solution of anagram, , survey can therefore check answer of respondent against solution each anagram.
as is, survey working perfectly: however, i'd allow respondents prematurely exit loop typing "exit" in response field, , redirect them next question block (the demographic questions).
this typically achieved using "skip" logic: however, skipping end of block not trick (the loop restarts). managed redirect them end of survey, not demographic question block.
is there way use javascript jump demographic block or exit loop , merge block prematurely? missing qualtrics option trick?
if still relevant you: needed same functionality , how solved it: first, define helper variable, call endloop
, initialize 0. set function change value of endloop 1 after people hit button, additionally add display logic question in loop showing them if endloop still 0 , hiding questions endloop 1.
this step-by-step instruction , javascript , html code.
the bold stuff need do, bulletpoints more detailled instruction how it.
1. before loop-and-merge define embedded data field called endloop
, initialize 0.
- go survey flow panel
- add new element > select embedded data field
- name field 'endloop'
- set value t0 number 0 click on link "set value now"
- make sure move before merge-and-loop block
2. each item in loop set display logic show them conditional on 'endloop' = 0
- go options menu of each question in loop
- select "add display logic"
- select "embedded data" first dropdown menu
- a new type field opens > name type
endloop
+ select "is equal to" + type 0 value
3. insert customized button page people should able opt-out. button runs user-defined function called setendloop() onclick.
- click on question button should appear
- on top-right of question text select "html view"
the code used is:
<input id="css-class-mybutton" onclick="setendloop()" value=" done " type="button">
if want change button text, change " done " in
value = " done "
4. define function setendloop() using custom javascropt change value of endloop 1 , emulate next button click
- go options menu of each question in loop
- select "add javascript"
the code used is:
/* endloop variable */ var endloop = "${e://field/endloop}"; qualtrics.surveyengine.addonload(function(){ /* hide previous , next button */ $('nextbutton') && $('nextbutton').hide(); $('previousbutton') && $('previousbutton').hide(); /* function: on click on user-defined button -> change field endloop */ var = this; setendloop = function(){ qualtrics.surveyengine.setembeddeddata('endloop', 1); that.clicknextbutton(); }; });
the button not have default style, thus, define custom css style button buttons of theme. class name button used here id="css-class-mybutton"
, use .css-class-mybutton{ ... }
in css.
hope helps.
Comments
Post a Comment