• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

Bridgehill Learning Solutions

Learning Solutions. Human Connections!

  • About
  • Services
  • Testimonials
  • Portfolio
    • Client Projects (Snap Shots)
    • e-Learning Samples
  • Resources
    • Voice-Over Narrators
    • My eBooks
    • Posts & Articles
    • Micro-Lessons
    • JavaScript
  • Contact

Converting a Learner’s Name to Proper Case in Storyline using JavaScript

Home » elearningMatters » Converting a Learner’s Name to Proper Case in Storyline using JavaScript
June 7, 2023 by Richard

To keep my skills in Storyline 360 current, I often try to assist others using the application when I can via the Elearning Heroes Forum. This week, I came across a post where someone wanted to use JavaScript to ensure the letter in the learner’s first and last name was capitalized regardless of what the learner typed into the Storyline text fields.

Update: After playing with the code a little more after initially making this post, someone on the forums mentioned that if you were to type jAne or JANE, the JavaScript code below would convert to JAne and JANE. To address this, I’ve updated the JavaScript code which can be seen under The Revised JavaScript Code. To continue working out loud here, I’ve left both for you to see.

The Storyline Variables

To make this happen, I created three text variables in Storyline 360:

  • Fname: Learner’s first name
  • Lname: Learner’s last name
  • Fullname: Learner’s first and last name (this appears on its own layer after the user clicks the Submit button.

The Original JavaScript Code

I triggered the following code when the user clicked the Submit button.

var player = GetPlayer();
var jsFname = player.GetVar(“Fname”);
var jsLname = player.GetVar(“Lname”);

var capitalizedFname = jsFname.charAt(0).toUpperCase() + jsFname.slice(1);
var capitalizedLname = jsLname.charAt(0).toUpperCase() + jsLname.slice(1);

var fullName = capitalizedFname + ” ” + capitalizedLname;

player.SetVar(“Fullname”, fullName);

The Revised JavaScript Code

var player = GetPlayer();
var jsFname = player.GetVar("Fname");
var jsLname = player.GetVar("Lname");

var capitalizedFname = jsFname.charAt(0).toUpperCase() + jsFname.slice(1).toLowerCase();
var capitalizedLname = jsLname.charAt(0).toUpperCase() + jsLname.slice(1).toLowerCase();

var fullName = capitalizedFname + " " + capitalizedLname;

player.SetVar("Fullname", fullName);

Storyline Triggers

Note: Button 1 is the submit button in this example.

Category: elearningMatters, JavaScript

About Richard

Experienced L&D Consultant | Instructional Designer | eLearning Developer | Articulate MVP/Super Hero | Author | Jazz Connoisseur

Previous Post:How to Guarantee Your Next eLearning Project Will Fail
Next Post:The Most Important Question You Should Ask Yourself

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ready to start your project?

Let’s talk and see how I can help!

Work With Me