Skip to main content
Participant
May 25, 2018
Question

Increment button for calculated field

  • May 25, 2018
  • 3 replies
  • 607 views

I'm pretty much a novice, but able to get some decent engineering calculation worksheets built.

I have a series of dependent calculations that after some user input calculate the depth of a modular water storage tank. The final depth result field has a calculation script and it set to read-only. I want to add plus/minus increment buttons to allow users to see what the water volume capacity will be if they decrease the depth by the one module (the value is 0.33).

I tried various scripts from forums, but none work. None give an error - they just don't work. I have a feeling because the rest of the calculations on the sheet are dynamic (i.e. if the user changes an input value, everything recalculates), I am not using the correct script. I did try "clearing" any value from the field in question...

Here is the scrip that I have in the button action javascript field (on mouse up):

var x = this.getField("RSD"); // this is the field that is initially calculated that I want to allow users to incrementally change

var y = (x -= 0.33); // decrease field RSD value by 0.33 on mouse up

if(x.value!=”||x.value!=null){x.value=”} // clear value in RSD

if(x.value==”||x.value==null){x.value=y.value} // assign y value to RSD

Or is it that I am missing a command to "write" to field RSD?

Any help/direction will be appreciated.

Thanks!

This topic has been closed for replies.

3 replies

Inspiring
May 28, 2018

One thing for sure, if RSD is automaticcaly caluclated (i.e. in a calculate script), you can't increase or decrease its value by just manipulating the result because the calculate event will fire after your intervention, resuming the value to what it was before.

Either you add an invisible "offset" field that will take part of your calculation and you can change its value with your buttons

Or

instead of a calculate script, you use the combination of a doc-level script called from the validation event of your input fields.  That way, will be able to manipulate the result without a calculate script thats fires everytime you do.

Bernd Alheit
Community Expert
Community Expert
May 26, 2018

MariBogi  wrote

...

var y = (x -= 0.33); // decrease field RSD value by 0.33 on mouse up

...

This will not decrease the value of field RSD.

Bernd Alheit
Community Expert
Community Expert
May 25, 2018

Type ctrl-j and look at the console.

MariBogiAuthor
Participant
May 25, 2018

This is the error:

SyntaxError: illegal character

5:Field:Mouse Up

Which is the illegal character in my script?

try67
Community Expert
Community Expert
May 25, 2018

You can only use "straight" quotes, not curly ones.