I have a responsive project that uses a text entry box for the user to make notes whilst progressing through the project. What I would like to do is append some text to this depending on the outcome of various interactions.
v_teb_notes=v_teb_notes + "\nMy heading\nMy text to add.";
I believe that "\n" should add the new line, but when I run this the code fails. In the browser console I see the error "SyntaxError: '' string literal contains an unescaped line break".
When I remove the "\n" the JS executes, but no line breaks are added.
v_teb_notes=v_teb_notes + "My heading My text to add.";
I am not sure what I am doing wrong. I have tried various options based on other threads here without success, including using the Scrolling Text Widget. I wonder if Captivate is doing something odd to the JS. This post from over ten years ago says that Captivate strips "\n" in Advanced Actions. I hoped this would not happen from JS, but since the JS is executed as an action maybe it does. This would explain the browser error. If so, is there a work around?
On a similar note, I cannot find a way to add a new line to a Captivate variable either. One thread recommended using HTML e.g. adding "<br/>" to the variable value, but that doesn't work.
Hopefully someone can help!
Fixed! It was the playBar. I have some JS used to control the playBar functionality in my other projects. I will need to review this because I am not using the playBar for this project.
Thanks as always.
I have just noticed that in SCORMCloud and Moodle that the function is not found. Here is the console error:
ReferenceError: updateTEBcharting is not defined
But it works in the CP preview.
I thought that CP would include the function in the export, but I assume it is not. I am probably missing something but not sure what!
The answer was to add the file in the same way as CPExtra to the index.html file. I should have realised that earlier!