March 22, 2023
Need Javascript Help
Comments
(4)
March 22, 2023
Need Javascript Help
Mike Wilday is the Manager of Learning Technology Solutions at Los Angeles Pacific University. He began using adobe captivate back in 2011 as an instructional media designer and continued using the product since. He developed an instructional media that won a Silver Omni Award titled I.S. Helpdesk - Help my computer is stuck. https://omniawards.com/recent-winners and currently works freelance designing custom captivate solutions for software simulations, websites, and graphic design. 
Guide 3 posts
Followers: 6 people
(4)

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!!!

4 Comments
2023-03-29 16:52:38
2023-03-29 16:52:38

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?

 

Like
(1)
>
MarkLassoff
's comment
2023-03-30 16:42:01
2023-03-30 16:42:01
>
MarkLassoff
's comment

Not crazy at all, Mark

That is a legit suggestion.
I have seen this and made the same suggestion many times in other postings.

Thanks for chiming in!

Like
2023-03-23 15:59:41
2023-03-23 15:59:41

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.

Like
2023-03-23 14:16:14
2023-03-23 14:16:14

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?

Like
Add Comment