looking for a way to find a word or phrase with in a text box reponse
Mar 10, 2015
Hello all.. I am admitting I am stumped. I have been trying to write some kind of code that will allow me to look for a phrase within a text answer and then set the layer to correct if it finds that phrase.. here is my code if it helps. TextEntry1 is the textbox where the answer is and is stored when the control looses focus (per the trigger).
var player = GetPlayer();
var anwser1 = player.GetVar("TextEntry1");
var untrue = "false"
var test = "true"
switch(anwser1)
{
case "bob"
player.SetVar("correctanwser",test);
break;
case "frog"
player.SetVar("correctanwser",test);
break;
case "test"
player.SetVar("correctanwser",test);
break;
default
player.SetVar("correctanwser",untrue);
}
alert(player.GetVar("correctanwser"));
6 Replies
Hi Sherman,
Welcome to the community! i will have to defer to the community for use of JavaScript, as it is not supported in Storyline. Hopefully someone can jump in to assist :)
I had done something similar a long time ago. Here is an example: http://dev.keypointlearn.com/xcl71_SL/TEBContains/
This script snippet here:
"var player = GetPlayer();
var rawString =player.GetVar("TextEntry");
var TEBcontains="false";
var searchString=rawString.toLowerCase();
if (searchString.match ("good") || searchString.match ("great") || searchString.match ("creative") || searchString.match ("awesome") || searchString.match ("interesting")) TEBcontains="true";
player.SetVar("Result",TEBcontains);"
searches a textentry variable for keywords like 'good', 'awesome' etc. and displays content based on that search. Seems like a simpler script than the one you are trying?
Michael Hinze, you could very well be the HERO I'm looking for!!!
I need to create script that will search for keywords like 'good', 'awesome' etc but instead of displaying content, it adds a value to an accumulating score variable. How easy is it to do this in script? Is it possible? xxx
Looks like Jo is getting some assistance here as well.
Thanks Leslie et al! Yes, Matthew has come up trumps with the exact script I'm looking for.
I'd like to express my appreciation for all the support this forum gives xxx
So glad to hear it Jo! I'm thankful for all of our community as well :)
This discussion is closed. You can start a new discussion or contact Articulate Support.