Forum Discussion

KN2026's avatar
KN2026
Community Member
2 days ago

Javascript/Trigger Help

Hello! I'm trying to set up an activity where learners complete a system screen/field (create your own code). The requirement is that it must be at least 2 characters and no more than 14 characters long. They don't need to include specific #s or letters. Based on the text entry field, I want the SL to evaluate the entry after the user selects the submit button and display incorrect/correct feedback layers based on the user's input. The user gets 2 attempts. I used JS and variables to set it up. But it's not working properly. I feel like this should be doable, no? Can anyone help me, please? If not, what other accessible options can I do? TIA!

3 Replies

  • KN2026's avatar
    KN2026
    Community Member

    Thanks! I will take a look. I really appeciate the help

  • Nedim's avatar
    Nedim
    Community Member

    KN2026​ 

    Here’s why your JS code isn’t working:

    1. In your script, you’re retrieving the text variable "TextEntryPG", but the correct name defined in the Storyline variable panel is "TextEntryPG1".
    2. The number variable "number_of_characters" is not defined in Storyline, so the script is throwing an error.
    3. The event handlers used to validate conditions are inappropriate; all validation should occur on a button click, as shown in the third screenshot.

    I’ve fixed all the issues and attached a working version for you to review.

  • ManojKumar5's avatar
    ManojKumar5
    Community Member

    Hello! KN2026​ 

    I’ve updated your file based on my understanding of the requirement. Please have a look and see if this works for you. I’ve also used a small amount of JavaScript. If you’d like to change or add the number of correct answers, you can do so from Form View—you can easily modify or add values there. Currently, the correct answer is “correct” (case-insensitive).

    Note: If the entered text is below 2 characters or above 14 characters, a message layer will appear. You can customize the graphics and text on that layer as per your requirement.

    Hope this helps—happy to support! 🙌