Beenden
  • Globale Community
    • Sprache:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

How can I create a "plus" and "minus" buttons to increase or decrease the value of a calculated numeric field?

Neu hier ,
Jan 08, 2018 Jan 08, 2018

Hi, I am a novice but have enough knowledge to have created several complex engineering calculation forms.

Currently I have the following situation and need assistance:

Field "volume required" = calculated based on user entry (other fields in the form)

Field "depth" = calculated as:  "volume required" / ("area" *2.32), taking that number and assigning it a value based on the range it is in (using if...else if)

Field "area" = user entered

Field "volume" = calculated as: "depth" * "area"

I want to add a "plus" and "minus" buttons on either side of the "depth" field which should allow users to increase/decrease the value of the "depth" field in increments of 0.33. I am assuming that once that i s done the "volume" field will update based on the now changed value of "depth".

I know how to create the buttons. I cannot seem to be able to come up with the script to get the buttons to manipulate the value of "depth". I created a hidden field which calculates the initial value for the depth and copied that value to the field that is visible on the form. I am trying to manipulate the visible field. The "volume" field is calculated based on the visible field.

I have this so far, but  it is not working, nor it is giving me an error. This is the script for the "plus" button to be executed "On Mouse Up".

(function () { 

    var RDP = this.getField("RS3DEPTHRow1").value;    // this is the "depth" - visible field which duplicates the value of RS3DEPTHRow1H (the hidden field)

    var UDP = RDP / 0.33;    // determining the range of the values

    var ADD1 = RDP + 0.32;    //some value ranges need to be increased by 0.32

    var ADD2 = RDP + 0.33;    //the rest of the ranges need to be increased by 0.33

 

    if  (UDP > 1 && UDP <= 2)  { 

        event.value = setField("RS3DEPTHRow1").valueAsString=='' ? '' : ADD1; 

    } else if (UDP > 6 && UD <= 7)  { 

        event.value = setField("RS3DEPTHRow1").valueAsString=='' ? '' : ADD1; 

    } else if (UDP > 11 && UDP <= 12)  { 

        event.value = setField("RS3DEPTHRow1").valueAsString=='' ? '' : ADD1; 

    } else  {  

        event.value = setField("RS3DEPTHRow1").valueAsString=='' ? '' : ADD2; 

    }

})();

I am assuming that once I have this resolved, I can apply the same code and change it to subtract for the "minus" button.

Is this even possible since I am trying to change the value of a calculated, read-only field?

Thank you in advance!

THEMEN
Acrobat SDK und JavaScript , Windows
1.8K
Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
LEGENDE ,
Jan 08, 2018 Jan 08, 2018

There is no built-in setField method. Is that something you created or did you intend to use the getField method?

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
Jan 08, 2018 Jan 08, 2018

I ”created” it as in I guessed. Is there any other way to get the “depth” field to be adjusted by pressing the “plus” or “minus“ buttons? A workaround?

I know there is a way to create global document scrips, but that‘s beyond what I have done.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Jan 09, 2018 Jan 09, 2018

Programming by guessing is never a good idea. You need to study the relevant API if you want to do it properly.

Use getField instead of setField.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Neu hier ,
Jan 09, 2018 Jan 09, 2018

Thank you!

Guessing was a desparate attempt on my part. I read through all the commands and still couldn’t get it to work. So here I am looking for expert assistance.

I still have not found out if what I am trying to do is possible.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Jan 09, 2018 Jan 09, 2018
AKTUELL

It is possible, but your code seems very complicated for the task you described. All you need is this, basically (for the plus button):

var f = this.getField("RS3DEPTHRow1");

f.value = Number(f.value)+0.33;

And for the minus button replace +0.33 with -0.33. That's it.

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines