Skip to main content
Participant
January 9, 2018
Question

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

  • January 9, 2018
  • 1 reply
  • 1883 views

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!

This topic has been closed for replies.

1 reply

Inspiring
January 9, 2018

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

MariBogiAuthor
Participant
January 9, 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.

try67
Community Expert
Community Expert
January 9, 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.