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

JavaScript subtract from a fixed number in adobe acrobat

New Here ,
Oct 26, 2024 Oct 26, 2024

Howdy everyone,

 

I need some help with this question. I have a form with 12 performance benchmarks. In the evaluation, you start with 100 points, and each benchmark deducts 5 points if anything is deemed unsatisfactory. I wrote some code, but I can't seem to get it to work. How can I make the "TotalScore" field start at 100 and have the first "5pts13" field start subtracting? All the other fields after that are working fine, so I'm almost there. Much obliged for your time.

 

// 100

var nA = Number(this.getField("5pts13").valueAsString);

var nB = Number(this.getField("5pts14").valueAsString);

var nC = Number(this.getField("5pts15").valueAsString);

var nD = Number(this.getField("5pts16").valueAsString);

var nE = Number(this.getField("5pts17").valueAsString);

var nF = Number(this.getField("5pts18").valueAsString);

var nG = Number(this.getField("5pts19").valueAsString);

var nH = Number(this.getField("5pts20").valueAsString);

var nI = Number(this.getField("5pts21").valueAsString);

var nJ = Number(this.getField("5pts22").valueAsString);

var nK = Number(this.getField("5pts23").valueAsString);

var nL = Number(this.getField("5pts24").valueAsString);

 

// Perform Calculation

var nDiff = nA - nB - nC - nD - nE - nF - nG - nH - nI - nJ - nK - nL;

 

// TotalScore

event.value = nDiff;

TOPICS
Create PDFs , JavaScript , Modern Acrobat , PDF
681
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 26, 2024 Oct 26, 2024

Try this:

var nDiff = 0;
for(var i=13; i<=24; i++){
var f = this.getField("5pts"+i).valueAsString;
if(f != "")nDiff += 5;}

event.value = 100-nDiff;

View solution in original post

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 ,
Oct 26, 2024 Oct 26, 2024

Try this:

var nDiff = 0;
for(var i=13; i<=24; i++){
var f = this.getField("5pts"+i).valueAsString;
if(f != "")nDiff += 5;}

event.value = 100-nDiff;
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 ,
Oct 26, 2024 Oct 26, 2024
LATEST

Oh my gosh!!! You are a beast!!! Yours was much simpler than mine, not that I'm an expert or anything. I’m most beholding to you ma’am!!! I can't thank you enough.

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