• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Captivate Javascript ChangeState

New Here ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

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");
}

Views

381

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Feb 03, 2021 Feb 03, 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");
}

 

Votes

Translate

Translate
Advisor ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

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");
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources