You can use the code below to create a JavaScript filter variable that can identify text responses with specific keywords
Requirements
- A Displayr document with text variables.
- Basic comfort with JavaScript. See: How to Use JavaScript in Displayr and JavaScript Fundamentals.
Please note these steps require a Displayr license.
Method
This code snippet can be used to make a filter which selects all respondents whose Text response matches a particular string (or strings). To use it, modify the first line of code to enter the desired search terms, and modify the second line to replace MY_INPUT_TEXT with the Variable Name of the Text variable you want to search. The text will be converted to lowercase, so you don't need to worry about searching for the same word in different cases. Once you have created your variable, make sure it is tagged as a Filter.
var _search_terms = ["hello", "hi"];
var _text = MY_INPUT_TEXT;
_text = _text.toLowerCase();
var _term_found = _search_terms.some(function (_term) { return _text.indexOf(_term) > -1; });
_term_found
Next