Expand my Community achievements bar.

SOLVED

Problem with checkbox and "if" & "else if" statement

Avatar

Former Community Member

Hi, i have got something like this:

if (this.rawValue=="0" ){

  app.alert("0");

  this.resolveNode("Circle1").presence = "hidden";

  this.resolveNode("cross").presence = "visible";

else if (this.rawValue=="1"){

  app.alert("1");

  this.resolveNode("Circle1").presence = "visible";

  this.resolveNode("cross").presence = "hidden";

  }

else{

  app.alert("2");

   this.resolveNode("Circle1").presence = "hidden";

  this.resolveNode("cross").presence = "hidden";

}

I set default position on neutral state. Values are default: on=1, off=0, neutral=2.

When i am clicking on my check box button there works only "on" (1) and "neutral" (2) state. "off" state is not working and i don`t know why.

Please help me with that.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Here is the form back to you: https://acrobat.com/#d=qiBnkcpRnPWxA5hokFXvQw.

I have tightened the script, but that was not the main problem. The issue was that the checkbox was on the Master Page and had a default value of neutral. Some objects on the Master Page, like checkboxes with default values and buttons, can misbehave when the form is relaid out (layout:ready event).

If you have a look at the form you will see that the objects on the Design Page behave as expected. However similar objects on the Master Page will revert to default everytime the layout:ready event fires. This has already been logged with Adobe.

I would recommend moving the objects to a Design Page or maybe use a dropdown instead of the checkbox.

Niall

View solution in original post

7 Replies

Avatar

Level 10

Hi,

Your script looks okay. What event are you using for the script? I would recommend the click event.

Make sure that the bound values for the checkbox match the values used in the script (Object > Binding palette). Also make sure that the language is set to JavaScript.

When previewing the form, open the JavaScript Console (Control+J) and when you interact with the checkbox, does an error show up in the console.

On a separate note, if the Circle1 object and the cross object are uniquely named then you would not need to resolve the node. This is not the problem with the script, but using a relative reference would make the script more efficient.

Niall

Avatar

Former Community Member

Is it not working. I changed from "change" to "click" with no success. "Off" state is showing for 1 second and it is automatically changing into "neutral" state (without my clicking). I am loosing my "off" state as I only have two option: "on" & "neutral" states (but i have set up three - on,off, neutral). One more thing is tha command app.alert("0"); is executed properly but next ones aren`t. This is wired becouse on other "if"s those two lines are executed properly. It is all set up in JavaScript console.

Avatar

Level 10

Hi,

I am guessing that there is a conflicting script somewhere. Can you share your file? If so upload it to a file sharing site, publish it and post the published URL here.

Niall

Avatar

Correct answer by
Level 10

Hi,

Here is the form back to you: https://acrobat.com/#d=qiBnkcpRnPWxA5hokFXvQw.

I have tightened the script, but that was not the main problem. The issue was that the checkbox was on the Master Page and had a default value of neutral. Some objects on the Master Page, like checkboxes with default values and buttons, can misbehave when the form is relaid out (layout:ready event).

If you have a look at the form you will see that the objects on the Design Page behave as expected. However similar objects on the Master Page will revert to default everytime the layout:ready event fires. This has already been logged with Adobe.

I would recommend moving the objects to a Design Page or maybe use a dropdown instead of the checkbox.

Niall

Avatar

Former Community Member

Could you tell me why this happen and what i should not place on Master Page? I thought that if i one page document that i should all place on Master Page. What is Master Page for if i can`t place there checkbox properly?

Thanks a lot. Your answers were very helpfull for me.

Avatar

Level 10

Hi,

I am glad you have it working.

Even with a one page form I would still create a Design Page and place most (if not all) of the objects on the Design Page. The Master Page is only really intended for objects that are to appear on all pages.

The behaviour is a bug (afaik) and I have logged it with Adobe last year. I don't have an update. I had an example showing the issue, but I can't find it at the moment.

Buttons are fine on the Master Page, unless you are changing their visual appearance. It now appears that checkboxes on the Master Page may be an issue as well. Other objects, textfields, numericfields appears to be okay.

Good luck,

Niall