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

Else if a mystery

Community Beginner ,
Mar 13, 2019 Mar 13, 2019

Copy link to clipboard

Copied

I have a form with 3 drop-down columns.  If have a value assigned to each option on each drop-down.  I want to compile the sum of all the drop-down columns in another column.  However, right now, I can't get my JavaScript to even work on the first column.  I've got the script below entered into the Custom calculation box and its not working at all.  Can anyone tell me what I've done wrong?

Also, assuming I a formula to work for the first column can I then just add a "+" to the end of the formula and then repeat the process for my next two columns.  Everything I know about JavaScript, I read on-line this morning so I'm worse than a novice.  Appreciate anyone's help.

var a=this.getField("Dropdowna").value;

if(a=="High Impact/ High Probability"){

  1. event.value=5;

}else if(a=="High impact/ Low probability"){

  1. event.value=4;

}else if(a=="Low impact/ High probability"){

  1. event.value=3;

}else if(a=="Low impact/ Low probability"){

  1. event.value=2;

}else if(a=="Conflict of Interest"){

  1. event.value=1;

}else if(a=="Click cell for drop-down"){

  1. event.value=0;
TOPICS
Acrobat SDK and JavaScript

Views

481

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
LEGEND ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

What error message do you see in the JavaScript console? If that's all there is, you will certainly get an error message.

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
Community Beginner ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

I got a syntax error on line 13 and then removed the squiggly parenthesis at the end of the line 12 string.  The error message went away but the calculation would only run on the first and last instance.  Meaning that when High Impact/ High Probability was selected, I got a "5" back and I got a "0" when Click cell for drop-down was selected.  Nothing in-between worked; the results always came back 5 or 0.  BTW - thank you for the response.

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
LEGEND ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

The { } signs (I call them braces but I don't know the right name for them) are needed in a lot of cases to go around things. In your case you shouldn't have removed the one at the start of the line, but added one at the end (or on the next line, that doesn't matter).

If you do that and get rid of the error, but still don't see what you expect, try adding some debugging code at the end like

app.alert ( "Here I am. a is " + a + " but a.event.value is " a.event.value ) ;

Hmm, on reflection, why do you use a.event.value rather than event.value? Is that what your working example used?

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
Community Beginner ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

I’m sorry.  I should’ve caught this at the time but I have no idea where those a.’s came from. I cut/paste the formula I had in the Custom calculation script box directly into the message box above and the a’s materialized on their own.

So, what you’re suggesting is that I move the bracket from the end of line 12 to the start of line 13?  I tried that and got this message, “SyntaxError: syntax error 13: at line 14.” Curiously, I counted and I only have 13 lines of script.  I checked to make sure I didn’t have any hard spaces at the end of the 13th line. So, is there something I’m missing that should be on a line 14?

Disregarding the line numbers (I just added them for a point of reference), this is how I modified the script based on my understanding of your previous response.  This version resulted in the syntax error message described above.

  1. var a=this.getField("Dropdowna").value;
  2. if(a=="High Impact/ High Probability"){
  3. event.value=5;
  4. }else if(a=="High impact/ Low probability"){
  5. event.value=4;
  6. }else if(a=="Low impact/ High probability"){
  7. event.value=3;
  8. }else if(a=="Low impact/ Low probability"){
  9. event.value=2;
  10. }else if(a=="Conflict of Interest"){
  11. event.value=1;
  12. }else if(a=="Click cell for drop-down")
  13. }event.value=0;

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
Community Expert ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

Remove } at line 13.

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
Community Beginner ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

I did and it gets me back to a situation where the script yields a result of either 5 or 0.  It won't register results for any of the options in between the first & last.  Therein lies my frustration; though I do appreciate the response.

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
Explorer ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

To better understand, you're wanting to just add the values of all the variables that are selected in the drop down boxes, and then show the sum of the values in a different column, yes?

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
Community Expert ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

What can you see when you add the app.alert?

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
Explorer ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

I went ahead and tried tackling this myself.

This code is a revised version that runs as an action script for each specific drop down box.

Here is the script for the drop down boxes where specific values should be selected:

var a = this.getField("Dropdown0");

var b = this.getField("Reveal");

global.gDrop0 = 0;

if(a.valueAsString == "High Impact/ High Probability"){

global.gDrop0 = 5;

}else if(a.valueAsString == "High impact/ Low probability"){

global.gDrop0 = 4;

}else if(a.valueAsString == "Low impact/ High probability"){

global.gDrop0 = 3;

}else if(a.valueAsString == "Low impact/ Low probability"){

global.gDrop0 = 2;

}else if(a.valueAsString == "Conflict of Interest"){

global.gDrop0 = 1;

}else if(a.valueAsString == "Click cell for drop-down"){

global.gDrop0 = 0;

}

b = b.setItems([global.gDrop0 + global.gDrop1 + global.gDrop2]);

I would be make sure to change the form field names to suit your needs, and for every other drop down box that needs to be calculated, add a new "global.gDrop" value.  So Dropdown0 would have a global.gDrop0, Dropdown1 would have a global.gDrop1, etc.

Of course this code isn't as streamlined as it could be, so any input would be great.

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
Community Beginner ,
Mar 14, 2019 Mar 14, 2019

Copy link to clipboard

Copied

Cool!!  Thank you all for the help; much appreciated.  Trying to learn JavaScript but I might find it easier if I tackled Greek.  I have a greater appreciation & respect for those of who can speak it (JavaScript that is).  Thanks again.

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
LEGEND ,
Mar 15, 2019 Mar 15, 2019

Copy link to clipboard

Copied

LATEST

I'd say you've done a lot in 2 days. Like learning Greek, don't expect to get far in a day, a week or a month... but study will give rewards.

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