Forum Discussion
Live character count of essay question box
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.
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_Hilliard11 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-7c311 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.
- ArrolLofton-7c311 months agoCommunity Member
Hello again and good morning. Really appreciate all the help and wanted to know if you are available for paid contract work? Thanks
- ArrolLofton-7c311 months agoCommunity Member
One more question, is it possible to use your script on multiple slides? Would there need to be a unique script for each slide (I know all of the text entry fields and variables will need to be unique), but is there anything else that would need to change in your script? There will be notes with text inputs on several slides in a row. Thanks.
- Nathan_Hilliard11 months agoCommunity Member
Since all the script does is find the first input field on the slide and attach an event handler to watch it, you should just need to place the script on each slide where you need to use it. You should clear the previous event handler first (done by the second script with the .dispose() call). The counter script creates a new handler and saves its reference each time it is called.
If you had more than one input field on a single slide, you would need to change the way the field is selected. Currently, elem[0] is thefirst one found on the slide. If there are more, you can reference them as elem[1], elem[2], etc. Otherwise, use a different selector.
- ArrolLofton-7c311 months agoCommunity Member
I think I figured out a way to use your script on multiple slides in a row, using the remove counter script that you had on the second slide in your original sample SL file, I applied that after the user would hit the save button, then on to the next slide and the counter starts again ... hope that makes sense.
Related Content
- 1 year ago