Skip to main content
edd97886174
Participant
May 28, 2018
Answered

Form Scripting Questions (multiple)

  • May 28, 2018
  • 1 reply
  • 1278 views

I would appreciate any assistance regarding several questions I have about scripting for a particular form.  I am NOT a coder (so please type slowly!).  I am currently using Acrobat Pro 11.0.23 on Windows 10.

Below is a screen shot of the planned form:

INFORMATION ABOUT THE FORM:

  1. Need to be able to check off all that apply – for example a typical response might be POSITIVE
         for:  Problem 1; Problem 5; Procedure 6; Procedure 10 and Option 10.
         (All of these POSITIVE). 
  2. For Calculation of the “FINAL  LEVEL” – this relies ONLY on the single HIGHEST Problem – or Procedure –
         or Management Option.
  3. In the case above – the Final Level would be HIGH because both Procedure 10 AND Option 10 were POSITIVE.
  4. The YES / NO field could be used to indicate that ANY of the responses at that particular level had
         been selected.  (This is not completely necessary – but would make it easier to see at a glance where
         the highest level had been met.)
  5. In another case where responses showed POSITIVE for Problem 6, Procedure 1, and Option 1 – the FINAL
         LEVEL would be calculated as MODERATE – because the Problem 6 was POSITIVE.
  6. QUESTIONS:
    1. What type of “check box”  or “text box” should precede the Problems, Procedures, and Options?
    2. How to script for a binary answer for YES / NO – either ANY of the fields in that level have
            been selected – or NONE of the fields in that level have been selected –
            i.e. 1=YES; 0=NO
    3. How to script the “FINAL LEVEL” box to choose the HIGHEST LEVEL that had a POSITIVE (YES)
            response. 
    4. Again – it does not matter whether 1 or ALL of the fields at a particular level are selected –
            ANY fields return a POSITIVE for that level.  (It would merely be “helpful” to see
            what had been chosen as POSITIVE at each level.)

THANK YOU to anyone who could give me some help/advice on this.

This topic has been closed for replies.
Correct answer try67

It seems fine... Are you seeing any error messages in the JS Console (Ctrl+J)? Are there no results at all, or are they incorrect?

If the latter, check the field calculation order.

Also, do not edit the code in the Edit All JavaScripts window. It's a recipe for problems. Only edit it under the field or the doc-level script.

1 reply

try67
Community Expert
Community Expert
May 28, 2018

1. Use check-boxes. Make sure to name them in a consistent manner and give them proper export values. It will help later on.

2. This will require a custom-made calculation script. Should it work for each row? Each category (Minimal/Low/Moderate/High)? Something else?

3. Again, this will require a script. It can use the results from the Yes/No fields, though.

edd97886174
Participant
May 28, 2018

TRY67 -

Thank you so much!   I'm pretty decent with copy and paste and your answer was great.

For some reason, I am not able to get the "FINALLEVEL" Text Box to populate with anything.

Everything else seems to work fine.

Here is a screen shot of the first-pass draft.  As you can see - a CHECK in any of the boxes converts the YES/NO to YES. (PERFECT!)

But, there is nothing in the FINAL LEVEL box.

This is the script from the FinalLevel Text Box:

Below is the entire script

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<Document-Level>
//<ACRO_source>EVALUATION</ACRO_source>
//<ACRO_script>
/*********** belongs to: Document-Level:EVALUATION ***********/
function checkFields(fields) { 
for (var i in fields) { 
var f = this.getField(fields); 
if (f.valueAsString!="Off") return "YES"; 

return "NO";
}

//</ACRO_script>
//</Document-Level>

//<AcroForm>
//<ACRO_source>FINALLEVEL:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:FINALLEVEL:Calculate ***********/
if (this.getField("HighLevel").valueAsSting=="YES") event.value = "HIGH"; 
else if (this.getField("ModerateLevel").valueAsSting=="YES") event.value = "MODERATE"; 
else if (this.getField("LowLevel").valueAsSting=="YES") event.value = "LOW"; 
else if (this.getField("MinimalLevel").valueAsSting=="YES") event.value = "MINIMAL"; 
else event.value = "";
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>HighLevel:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:HighLevel:Calculate ***********/
event.value = checkFields(["Prob010",  "Proc010", "Opt010"]);
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>LowLevel:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:LowLevel:Calculate ***********/
event.value = checkFields(["Prob3",  "Proc3", "Opt3"]);
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>MinimalLevel:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:MinimalLevel:Calculate ***********/
event.value = checkFields(["Prob1",  "Proc1", "Opt1"]);
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>ModerateLevel:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:ModerateLevel:Calculate ***********/
event.value = checkFields(["Prob7",  "Proc7", "Opt7"]);
//</ACRO_script>
//</AcroForm>

edd97886174
Participant
May 31, 2018

It seems fine... Are you seeing any error messages in the JS Console (Ctrl+J)? Are there no results at all, or are they incorrect?

If the latter, check the field calculation order.

Also, do not edit the code in the Edit All JavaScripts window. It's a recipe for problems. Only edit it under the field or the doc-level script.


Perfect.

Got it working.  Thanks again!