Forum Discussion
Build Custom Search within Storyline using JavaScript
Hi Holly,
Thanks for reaching out with this question. You should be able to accomplish this using the JavaScript programming above and triggers to go to the specific slide(s) when the Storyline placement variable is equal to the appropriate number(s).
Can you send me a few of the terms and phrases you want to include? I can show you how to integrate those terms and phrases into the code.
Hi Holly,
I see you posted in an article that one of your phrases is: "bookable resource". I added basic text around this phrase to show how it would work.
Getting Set Up In Storyline:
- Add your search text entry field
- Add the text variable: searchfield - Initial Value = (Blank)
- Set searchfield as the variable associated with the text entry field
- Add number variable: placement - Initial Value = 0
- For ease of programming, add a reference to the placement variable on a visible slide - %placement%
Add JavaScript Trigger to Action that allows the user to search (ex. button next to text entry field):
var player = GetPlayer();
var parameters = player.GetVar("searchfield");
var lower = parameters.toLowerCase();
var key = "text1 text2 bookable resource text3 text4";
var termlocation = key.search(lower);
player.SetVar("placement",termlocation);
Test the programming - Note: Must publish to test JavaScript programming
- Enter each search term and/or phrase in the search bar and complete the action that triggers the JavaScript trigger.
- Note the value of the placement variable as each search term/phrase is entered. bookable and bookable resource would return the same value as this functionality looks for the position where the entered word or phrase is found in the overall text string.
For the example above, the placement variable would have the following values when these terms are entered:
text1 = 0
text2 = 6
bookable = 12
resource = 21
bookable resource = 12
text3 = 30
text4 = 36
Add triggers within Storyline to complete the desired action when the placement variable = the appropriate amount.
Let me know if this answers your questions or if I can be of additional assistance.