• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help. Want a field to show a minimum

Explorer ,
Sep 13, 2019 Sep 13, 2019

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

TOPICS
PDF forms

Views

361

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2019 Sep 14, 2019

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2019 Sep 14, 2019

Copy link to clipboard

Copied

I would suggest:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2019 Sep 14, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 14, 2019 Sep 14, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2019 Sep 14, 2019

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);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 14, 2019 Sep 14, 2019

Copy link to clipboard

Copied

LATEST
Thank you for your help as well. The previous post worked out ok. Just for the record, I tried the formula and it came up with a syntax error. "Missing ; before statement 5: at line 6".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines