Copy link to clipboard
Copied
So, here's my problem. I have for different Variables var A, var B, var C and var D, with an output box. I am trying to have it where the user inputs a number in one var and it appears on the output box, so if the user inputs 2 in var A and only on var A then it will show up in the ouput box, and the same for the other variables. I've tried this script but was only able to make it work for var A and var B, var C and var D did not work. thanks for the help.
var A = this.getField("VR1").value
var B = this.getField("VR2").value
var C = this.getField("VR3").value
var D = this.getField("VR4").value
if (B==0) event.value= ((A));
if (A==0) event.value= ((B));
if (D==0) event.value= ((C));
if (C==0) event.value= ((D))
Copy link to clipboard
Copied
If all the fields are blank, except one, then adding them together (i.e., aggregating them), will result in a value that matches the filled field.
var A = this.getField("VR1").value;
var B = this.getField("VR2").value;
var C = this.getField("VR3").value;
var D = this.getField("VR4").value;
event.value = A + B + C + D;
However, if more then one field is filled, then you need a strategy to prioritize which one is selected for the output field.
Or, if you want to prevent more than one from being filled, then you need a strategy to clear the other fields when a value is entered into one of them.
It's your choice.
Copy link to clipboard
Copied
Your description is not very clear, to me at least. What should happen if the user fills in more than one field? A & C? Or A & B? Or A & C & D? Or all four? etc.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
So, if all boxes are 0 except for box A, and the user enters a number into box C, then A should be set to zero? So all boxes except one contain a zero?
Copy link to clipboard
Copied
No, the users know that only once box will have to have a value, each one of those 4 boxes are for a specific task, and they will only do one of those task per form. So, if they perform task A then only box A will have a value, and that value should carry ou to the output box.
Copy link to clipboard
Copied
Use Bernd's scrpt. Since you know that users will only enter a value into one field, there is no need to do any checking. Just add them all up.
Copy link to clipboard
Copied
so, what does the Bernd's script look like for my scenario. Thanks.
Copy link to clipboard
Copied
You can't trust that people won't fill in multiple values. You have to actively prevent them from doing so, either by resetting the other fields, or by disabling them when a value is entered into one of them.
If you do that then all you would need to do is aggregate the four values into a single string (replace "0.0" with a blank string), to get what you asked for.
Copy link to clipboard
Copied
You can use:
event.value = A + B + C + D;
Copy link to clipboard
Copied
let me state that I am not a programer and your help is appreciated. I tried to use this script, but was only able to make the firs two lines work.
var A = this.getField("VR1").value
var B = this.getField("VR2").value
var C = this.getField("VR3").value
var D = this.getField("VR4").value
if (B==0) event.value= ((A));
if (A==0) event.value= ((B));
if (D==0) event.value= ((C));
if (C==0) event.value= ((D))
how and where would I use your suggestion? thanks
Copy link to clipboard
Copied
If all the fields are blank, except one, then adding them together (i.e., aggregating them), will result in a value that matches the filled field.
var A = this.getField("VR1").value;
var B = this.getField("VR2").value;
var C = this.getField("VR3").value;
var D = this.getField("VR4").value;
event.value = A + B + C + D;
However, if more then one field is filled, then you need a strategy to prioritize which one is selected for the output field.
Or, if you want to prevent more than one from being filled, then you need a strategy to clear the other fields when a value is entered into one of them.
It's your choice.
Copy link to clipboard
Copied
that worked like a charm, thank you for your help.
Copy link to clipboard
Copied
If only one field will be filled you don't need script for that, you can use built in calculation, under 'Calculate' tab select 'Value is the', leave as sum(+) and click on 'Pick' to select your fields.
Copy link to clipboard
Copied
[MOVED TO THE ACROBAT DISCUSSIONS]