Getting errors with simple javascript commands.
I’m working on a simple Javascript project that should be able to send a variable value to a variable in the project and jump to the next slide but I am getting all kinds of weird javascript issues.
Here is the code:
window.cpAPIInterface.setVariableValue(“q01”, “1”);
window.cpAPIInterface.next();
Basically, it should set the variable in captivate and jump to the next slide.
I’ve checked the variable value and tried the value of 1 with and without quotes, even tried adding text to the value and am getting the following errors.
I keep getting several random errors. Mostly consisting of…
SyntaxError: missing ) after argument list
at eval (anonymous)
at a.runJavascript (eval at e (CPXHRLoader.js:37:226), <anonymous>:643:175)
at eval (eval at executeAction (eval at e (CPXHRLoader.js:37:226)), <anonymous>:1:4)
at cp.Movie.executeAction (eval at e (CPXHRLoader.js:37:226), <anonymous>:965:432)
at b.clickSuccessHandler (eval at e (CPXHRLoader.js:37:226), <anonymous>:890:426)
at b.clickHandler (eval at e (CPXHRLoader.js:37:226), <anonymous>:889:167)
at b.ch (eval at e (CPXHRLoader.js:37:226), <anonymous>:889:225)
at f (eval at e (CPXHRLoader.js:37:226), <anonymous>:255:186)
at a.handleClickExternal (eval at e (CPXHRLoader.js:37:226), <anonymous>:258:274)
at a.handleClick (eval at e (CPXHRLoader.js:37:226), <anonymous>:259:327)
but I don’t see any errors in the javascript and I followed code I used in other projects. I uploaded the project to the internet and everything. Do I have to do something else like call a variable and set it then, publish it to captivate with the variable as the value. This doesn’t make sense. I thought this would be simple and easy… I can get a console.log(“testing”); call to run but it won’t push the variable value or jump to the next slide. HELP PLEASE!!!
Hi Michael– This is going to sound crazy.
The error indicates that you’re not sending the expected number of parameters to the method window.cpAPIInterface.setVariableValue().
Inside the arguments in the parenthesis are you using straight quotes (“) or typographers’ quotes (the curved and titled ones)? If you copied the code from somewhere, chances are that there are typographers’ quotes around your parameter values causing an error. These have different character codes under the hood.
Can you try just changing out the quotes and let me know if this works?
Are you using an external file or working with the Execute JavaScript box within Captivate?
I prefer to code everything within Captivate.
My code would look like this.
q01=1;
cp.goToNextSlide();
Lieve asks a good question – is it defined in Captivate?
I define variables in Captivate if I will use them across slides or display them. If they remain confined to a particular slide or function I do not.
Maybe a JS expert will pop in. Of course I tested it out but cannot reproduce any error. Captivate present version doesn’t know the difference between a string and a number, both “1” and 1 work for me (I rarely use that command to set an exact value, mostly I use it for random numbers).The Next command also works fine for me.
Just one question: did you define the variable q01 in Captivate?
You must be logged in to post a comment.