Forum Discussion
Live character count of essay question box
Hello again, found an issue that prevents this from working. If there is another javascript attached to another trigger on the same slide, it stops working, any ideas? Thanks
I suppose it depends upon what the script is doing. All this script does is setup a mutation observer (event handler) that watches for changes to the value of the input box. When the string changes length, the counter text is updated. The script on the second slide disconnects the observer, since it is no longer needed. Can you post the .story file you have an issue with? If not, at least a link to the published Review 360 demo and the script text would be helpful.
- ArrolLofton-7c39 months agoCommunity Member
Hello again, I have attached a sample storyline file. You will see a slide trigger at the top with Javascript on it, that is ok now. Initially, I had put your script at the slide trigger level too, like in your sample, and that is when it would stop working. With your script on the text entry field, all works ok, until we add another Javascript to the Save button object, and now your script doesn't work. We still need to limit the text entry to 1200 characters and also trigger the warning if they reach the max characters too, not sure if we need to use Javascript for those operations as well. Thanks again for your help on this, it is very much appreciated.
- Nathan_Hilliard9 months agoCommunity Member
I looked at your file and I've attached a modified version here. The script to count the characters does work and it doesn't matter where it's placed, as long as it's after the LMS loading script. I moved it back to the timeline start position for convenience.
The reason your scripts were stopping the function is because they contained some errors. When JS stops due to an error, it can stop some of the other scripts on the page as well. The notable errors were:
- The first comment line of the button script was not actually commented (missing '/').
- The variables in the scripts did not match the variable names of the SL variables.
The script was also storing the TextEntry1 variable in the LMS when it needed to store the UserNotes variable.
Have you actually used these scripts before? I ask because the method used to get the lmsapi assumes its location in the DOM. For example, in my LMS the api is at a different parent level than what was specified in the script. I added a function to the begining of each script that checks multiple levels until it locates the correct lmsapi level. You might want to use that in the future.
Anyway, I published the modified version to SCORM 1.2 and uploaded to my LMS to test it. It worked as expected, counted the text, and stored/retreived the typed data.
I also added one line to the counter script that updates the counter when initializing the event handler, so reloaded values from the LMS show the correct length.
Make sure to test in your LMS since the LMS functions will not work elsewhere. You might consider adding a test for if the LMS is present, and adding conditionals to the LMS function calls so you can test your code in Review more easily.
- ArrolLofton-7c39 months agoCommunity Member
Hi again and thanks for all the additional help. I am kind of just helping out to get a solution for this, I am no Javascript expert, kind of techie but all the other experts are busy working on other projects.
Related Content
- 11 months ago