Copy link to clipboard
Copied
I accidentally posted this previously with the wrong tags. I couldn't see any way to delete it for some reason. My apologies.
I'm trying to get the field "rp" to show a minimum value of 2, even if the calculations are less than 2. This script is an attempt to get this value for the field "rp"
For example:
when "val1" = 1
and "val2" = 1
The result will be 1.5 (rounded down to 1) but I want a minimum displayed value of 2. When either "val1 or val2" are 2 or more, everything works fine. It's only when they are both set to 1 that I need it to display a minimum value of 2 in "rp".
var val1 = this.getField("level").value;
var val2 = this.getField("keyabmod").value;
event.value = Math.floor((val1 / 2) + val2);
Thanks for any help,
Nic
Copy link to clipboard
Copied
Try this:
var val1 = Number(this.getField("level").valueAsString);
var val2 = Number(this.getField("keyabmod").valueAsString);
if (val1 == 1 && val2 == 1) event.value = 2;
else event.value = Math.floor((val1 / 2) + val2);
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Try:
var val1 = Number(this.getField("level").valueAsString);
var val2 = Number(this.getField("keyabmod").valueAsString);
event.value = "";
// process only if one value has a value;
If(val1 != 0 || val2 != 0) {
// compute possible result;
var nTest = (val1 / 2) + val2;
// enter at least 2 or the test result;
event.value = Math.max(2, nTest);
}
You may need to modify the code based under what conditions you wan the calculation to occur.
Copy link to clipboard
Copied
Thank you. This works perfectly.
var val1 = Number(this.getField("level").valueAsString); var val2 = Number(this.getField("keyabmod").valueAsString); if (val1 == 1 && val2 == 1) event.value = 2; else event.value = Math.floor((val1 / 2) + val2);
I really wish I could learn this. I need a free source for acroform stuff. One was suggested that requires a subscription and I'm on disability and don't have that kind of cash to spend. Thank you very much for your assist.
Copy link to clipboard
Copied
Assuming the calculation will occur when at least one value is not empty.
var val1 = this.getField("level").value;
var val2 = this.getField("keyabmod").value;
event.value = "";
// process only if one value has a value;
If(val1 != 0 || val2 != 0) {
// compute possible result;
var nTest = (val1 / 2) + Number(val2);
// enter at least 2 or the test result if greater;
event.value = Math.max(2, nTest);
}
Copy link to clipboard
Copied