Skip to main content
Participant
February 3, 2021
Answered

Captivate Javascript ChangeState

  • February 3, 2021
  • 3 replies
  • 639 views

Hello,

 

I have a problem with changeState in Captivate and hope you can help me. I have 2 Images as buttons. Every button has 3 States, a normal, clicked, and done and I am trying to change the state of them.

 

When a button is clicked so it's variable gets +1 and when you click again it get's -1. The idea is when I click on button 1 I want to check via Javascript if button 2 == 1 if yes then it should change the state to Done. Unfortuantley, it doesnt work. Here my code:

 

if(zug_state_2== 1){
zug_state_2= 0;
cp.changeState("img_1_sifa","Done");
}

    This topic has been closed for replies.
    Correct answer TLCMediaDesign

    Is this JS being executed in the action that sets the variables?

     

    I would log the value of zug_state_2, like so:

    console.log(zug_state_2, zug_state_2== 1)

    if(zug_state_2== 1){
    zug_state_2= 0;
    cp.changeState("img_1_sifa","Done");
    }

     

    It may be a string instead of a number so you could try:

     

    if(Number(zug_state_2)== 1){
    zug_state_2= 0;
    cp.changeState("img_1_sifa","Done");
    }

     

    3 replies

    MomoGAuthor
    Participant
    February 3, 2021

    Thanks, I could use the console.log to check that the variable I used was wrong! After I changed it, it worked!

    TLCMediaDesign
    TLCMediaDesignCorrect answer
    Inspiring
    February 3, 2021

    Is this JS being executed in the action that sets the variables?

     

    I would log the value of zug_state_2, like so:

    console.log(zug_state_2, zug_state_2== 1)

    if(zug_state_2== 1){
    zug_state_2= 0;
    cp.changeState("img_1_sifa","Done");
    }

     

    It may be a string instead of a number so you could try:

     

    if(Number(zug_state_2)== 1){
    zug_state_2= 0;
    cp.changeState("img_1_sifa","Done");
    }

     

    Stagprime2687219
    Legend
    February 3, 2021

    I think we would need to expand the view here.

    The code you provided is fine as far as I can see.

    Perhaps something is not named correctly. Remember that the names are case sensitive. (done  vs  Done)

    Did you remember to assign the variable with a value of 1 when the button is clicked?