Wakefield's Daily Tips

Splitting textbox.text online

If you want to split the text from an editable textbox into words (for example in a free recall task) online, there there are two issues that need to be overcome.

  1. The Python function .split() which splits on any whitespace is auto translated into .split(" ") which only splits on spaces.

  2. The text in the data file has no new line breaks at all. It appears the the newline characters in an editable textbox are stripped from the text when the routine ends.

To solve the first issue, define a split function in Before Experiment.

Python

def split(item):
    return item.split()

JavaScript

function split(item) {
    return item.split(/[\s\n]+/);
}

To solve the second issue, the split function must be called in Each Frame code at the point the routine is ending. To do this, put the code component at the bottom of the routine.

if continueRoutine == False:
    words = split(textbox.text)