Javascript not triggering

I'm trying to eliminate having to put in double entries for every possible answer, one without a trailing space and one with.

Whatever is entered into the textentry box, I want it converted to all CAPS and then I want all leading and trailing spaces removed.   Acceptable answers would be:

I am





You are


Here is my code, I've tried adding it to the textentry loses focus event and to the presses submit button event.

var p = GetPlayer();
var textentry = p.GetVar("TextEntry");
var newtextentry = textentry.toUpperCase();
p.SetVar("TextEntry",newtextentry.replace(/^\s+|\s+$/g, ')');


Nothing seems to be triggering at all.   I should be able to type in "i am      " with a bunch of extra spaces and it changes to "I AM" with no extra spaces.

15 Replies
Jerry Beaucaire

Didn't know that was a thing.   Saw this in there:


Uncaught SyntaxError: missing ) after argument list
2app.min.js:3 Uncaught TypeError: Cannot read property 'setAttribute' of null
at e.determineChildMouseBehavior (app.min.js:3)
at e.whenHtmlReady (app.min.js:3)
story_html5.html?lms=1:1 Uncaught (in promise) DOMException
2app.min.js:3 actionator::exeJavaScript - this.execUserJs is not a function
(anonymous) @ app.min.js:3
story_html5.html?lms=1:1 Uncaught (in promise) DOMException

Jerry Beaucaire

I've given up on the CAPS thing, now just trying to get a TRIM script to trigger and run, still not doing anything.  I'm stuck.


var p = GetPlayer();
var textentry = p.GetVar("TextEntry3");
var newTextentry = textentry.replace(/^\s+|\s+$/g, '');


taken from this page: 

Jerry Beaucaire

OK, it appears it actually WAS working, but only when the SUBMIT button was pressed.  I needed to add a duplicate trigger for the ENTER key and now it seems to work for all entries.

Phew....  and yes, you were correct, I pasted the snippet above from the original site, in my project it was newTextentry.   ;)

Jerry Beaucaire

This works for me but only after publishing.   I've added triggers to execute the JS on pressing the ENTER key or pressing the SUBMIT key.

This only removes spaces at the front or back of the text string.

var p = GetPlayer();
var textentry = p.GetVar("TextEntry");
var newTextentry = textentry.replace(/^\s+|\s+$/g, '');

Jerry Beaucaire

Yes, Julie.  You indicated you didn't know where/how to put javascript to run on a triggered moment.  When I look in storyling the "Execute Javascript" trigger action is listed in the MORE section.

Adjust Variable
Pause Timeline
Resume Timeline
Jump to URL/File
Send email to
Execute Javascript