Forum Discussion

BridgetODell's avatar
BridgetODell
Community Member
7 years ago

Build Custom Search within Storyline using JavaScript

Using JavaScript, follow these instructions to add a Custom Search Engine to your course. In 2018, I shared this functionality via a 5 minute Spark Presentation at the Chicago eLearning & Technology Showcase in Naperville, IL.

 

Note: The instructions below were programmed using Articulate Storyline 2, and I have ensured they are applicable in Storyline 3 and Storyline 360 as well. These instructions are specific to jumping to a specific slide when a user enters specific search terms, however you could also have other actions occur when this happens, such as displaying a layer or changing an object's state to show applicable search results.

 

Build Custom Search Engine in Storyline:

1. Add a "search" slide (your slide 1.1) in Articulate Storyline.

2. On this slide, add a Text Entry Field and edit the variable associated with the entry field. Click the + sign within the variable popup to add a new variable. 

3. Name the new variable: searchfield  and make it a Text variable with an initial value of (blank).

4. Also on your search slide, add a button and add "Search" as the button's text.

5. Add a new variable: placement  and make it a Number variable with an initial value of 0.

6. Add a reference to the placement variable on your slide by adding a text box and entering the text: %placement% into the text box. 

7. Create your content slide(s). 

Optional: On each content slide, add a button which contains a trigger to jump to slide 1.1 when the user clicks it so that the user can easily return to the search slide.

8. For each content slide, think about the keywords that the user might enter into a search bar in order to find that content. List out these keywords in a notepad and make them all be in lowercase letters. (JavaScript is case sensitive and this example only works with lowercase letters for ease of programming).

9. Return to the search slide and edit the search button's default trigger

Action: Execute JavaScript

Script: 

var player = GetPlayer();

var parameters = player.GetVar("searchfield");

var lower = parameters.toLowerCase();

var key = "(insert your slide's keywords here inside the quotes without the parenthesis)";

var termlocation = key.search(lower);

player.SetVar("placement",termlocation);

When: User Clicks

Object: Search Button

On Condition: searchfield != Not equal to (blank)

 

10. Publish your course to HTML to test it. 

Note: You cannot preview JavaScript programming in Storyline, you have to publish it to test it.

11. Enter each of your keywords, one at a time, into the text entry search field and click the search  button.

12. Note the value of the placement variable reference on the slide for each of your keywords. 

Ex. keyword 1 = 0  keyword 2 = 10  keyword 3 = 20

13. On the search slide, add a trigger on the search button to:

Action: Jump to slide

Slide: (appropriate content slide corresponding to the first keyword(s))

When: User Clicks

Object: Search button

On Condition: 

placement == Equal to (insert placement # corresponding to keyword) 

Ex. Jump to slide 1 when placement == Equal to 0

14. Repeat step 13 as needed to add any additional triggers to jump to additional slides when the placement variable is equal to the correct corresponding keyword #.  

Ex. Jump to slide 2 when placement == Equal to 10

15. Remove the placement variable reference (%placement%).

16. Publish to HTML.

Finished result: User enters a keyword into the text entry search field, clicks search button, and the corresponding slide displays.

 

Happy programming!