require number of characters in text entry- storyline 2

Dec 29, 2017

My client is asking me to require a minimum number of characters in a text entry. I hate it, as I've told them, since students could just press the letter L 90 times to meet a 90-character requirement as it's an open ended question so there's no 'right' answer. But they still want it. Is there a way to make this happen in storyline 2? Thanks in advance!

4 Replies
Bob O'Donnell

Gotta' love client requests. Don't forget to search the database as there are a couple of posts on using JavaScript to track character entries. See if this one gets you close. Go toward the bottom of the post and see Mark Bennett's posted example - TextEntry-Length.story.

https://community.articulate.com/discussions/articulate-storyline/word-count-within-a-data-entry-field

jen j

Thanks for the link! I can get it to work on one slide, but I don't understand what the heck I'm doing enough to modify it to work on more than one slide. If I use the same javascript on multiple slides then it's already counted on the first one and doesn't start over. Argh. 

Here's the javascript I'm using that I got from the linked discussion/example

var player = GetPlayer();

var 2Tweet= player.GetVar("2Tweet");
var numChars= 2Tweet.length;
player.SetVar("2tweetLength",numChars);

Can someone pls tell me what I'd modify to reuse this on multiple slides??

Safurah Abdul Jalil

I know this is an old post (like half a year ago) but I thought I'd help answer it in case it'll help others looking for a similar answer. 

In your javascript code, "2Tweet" is the name of the variable the text entry field is linked to. When you create a text entry field, it will automatically create a variable called e.g. TextEntry1 to store text that has been typed into the text entry field. You can rename/reassign this variable (e.g. in this case, it's renamed to "2Tweet" or reassigned to another Text variable called "2Tweet"). 

To reuse this code in other slides, simply replace '2Tweet' with the name of the text variable that is linked to the particular text entry field in that current slide. You can find the variable name under the 'Triggers' panel - select the text entry field to help you see better as it should then highlight the trigger script (see attached image - I've highlighted the text variable name).

So for example, if I want to count the characters in my 'Text Entry 1' field (which in the attached image shows that it's linked to a text variable called  to "TextEntry1"), this is how you modify the js code:

var player = GetPlayer();

var TextEntry1= player.GetVar("TextEntry1");
var numChars= TextEntry1.length;
player.SetVar("TextEntry1",numChars);

Hope that helps.

 

This discussion is closed. You can start a new discussion or contact Articulate Support.