Parse text entry line breaks as separate items?

NickVEICNickVEIC VermontCommunity Member Qubie ✭

Parse text entry line breaks as separate items?

I want respondents to enter a list of items of any length and have each of these items captured as its own value. Probably list lengths are 0-10 items.

I know I could do this with a form question (one item per form field), or with a single essay style field after exporting data (run a script that identifies each line break as a separate item). But is there a way to accomplish something like that second option within Qualtrics? I was looking for a way to have Qualtrics recognize each line break in a text box as a distinct item but that doesn't seem to be possible.

Example below. Any suggestions?

Respondent enters this

My data would be structured like this
Response 1: cat
Response 2: dog
Response 3: echidna
Response 4:
Response 5:

Best Answers

  • flebfleb Czech Republic Sage ✭✭✭
    Accepted Answer

    Hi @NickVEIC,
    you're able to distinguish lines using JavaScript. You can divide your text into array using line breaks and than send your particular responses to distinct embedded filed (which must be defined in the survey flow manually).
    You could use something like following script. Be aware that if your respondent enters 11 or more lines, the remaining ones won't be stored. You could either constrain your textarea element or save it somewhere else by modifying the script.

        var my_text = document.getElementById(this.questionId).getElementsByTagName('textarea')[0].value.split('\n');
        var i = 0;
        var j;
        for (; i < my_text.length; i++) {
          j = i + 1;
         Qualtrics.SurveyEngine.setEmbeddedData( 'my_field' + j, my_text[i]);
  • flebfleb Czech Republic Sage ✭✭✭
    Accepted Answer

    Hi @NickVEIC,
    you're right with the field names. Regarding to the 11th and higher lines, I've just realized, that the text of the whole field will be stored as a response anyway, so you don't need to implement something else in fact. Just create your fields and copy-paste the code.
    Good luck!


  • NickVEICNickVEIC VermontCommunity Member Qubie ✭

    Hi @fleb,

    Thanks for the idea! Sounds like a very useful approach. Unfortunately I have absolutely zero skills with JavaScript. Using your code as it's written, should the manually defined embedded data fields be called "my_field0," "my_field1," etc.?

    If I'm off base with that, I may have to just hang on to this idea for a time at which I'm familiar enough with JavaScript to make use of it!

Sign In to Comment