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

Please help with simple conditional equation

New Here ,
Feb 11, 2018 Feb 11, 2018

I'm not familiar with coding languages at all, but I'm trying to make a conditional equation on an Acrobat form.  This is what I've pieced together by looking at other forums.  Could I have someone fix whatever is wrong with it? Please. There are just the 3 values from the "size" field that return one of the 3 values for the "size mod" field.

if (Size = "M") {

    Size Mod = "0";

}

else if (Size = "L") {

    Size Mod = "-1";

}

else if (Size = "S") {

    Size Mod = "1";

}

TOPICS
Acrobat SDK and JavaScript
467
Translate
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
Community Expert ,
Feb 11, 2018 Feb 11, 2018

There's quite a lot wrong with this code. Use this, instead (place it as the custom calculation script of the "Size Mode" field):

var size = this.getField("Size").valueAsString;

if (size == "M") {

    event.value = "0";

} else if (size == "L") {

    event.value = "-1";

} else if (size == "S") {

    event.value = "1";

}

Translate
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 11, 2018 Feb 11, 2018

Acrobat accepted that equation. However, when I enter one of the 3 values for "Size", nothing happens to "Size Mod". Am I missing something?

Translate
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
Community Expert ,
Feb 11, 2018 Feb 11, 2018

Check the JS Console (Ctrl+J) for error messages.

Translate
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 11, 2018 Feb 11, 2018

Nothing there

Translate
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
Community Expert ,
Feb 11, 2018 Feb 11, 2018

I'll need to see the file to be able to help you further.

Can you share it with us via Dropbox, Google Drive, Adobe Cloud, etc.?

Translate
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
Community Expert ,
Feb 11, 2018 Feb 11, 2018

I got the file. Why did you edit the code I provided? There's a reason why I wrote it the way I did.

Translate
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 11, 2018 Feb 11, 2018

I originally cop and pasted it, but when it was staying blank I tried tinkering with it to see what effects it’d have

Translate
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
Community Expert ,
Feb 11, 2018 Feb 11, 2018

Use the code I provided as-is and it will work.
Note that JS is case-sensitive, though, so if you enter "s" into the Size field it won't work. Only "S".

Translate
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 11, 2018 Feb 11, 2018

You tried it and it worked?

Translate
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
Community Expert ,
Feb 12, 2018 Feb 12, 2018
LATEST

Yes.

Translate
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