Skip to main content
CGC4x4
Participant
October 26, 2024
Answered

JavaScript subtract from a fixed number in adobe acrobat

  • October 26, 2024
  • 1 reply
  • 624 views

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;

This topic has been closed for replies.
Correct answer Nesa Nurani

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;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
October 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;
CGC4x4
CGC4x4Author
Participant
October 26, 2024

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.