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

Javascript writing issue

Participant ,
Oct 04, 2018 Oct 04, 2018

Hello everyone!  It's been quite some time since I've posted a Javascript question.  I've spent hours trying to figure this one out and unfortunately I'm stuck!  If anyone can offer and suggestions/solutions to my isse I would greatly appreciate it.  My goal is simple, writing the code is difficult.  The scenario is:  I have two fields that I'm looking at.  B231 and B232.  If B231 is $10 or less then the answer is $0.  If B232 is $10 or less the answer is $0.  If B231 is greater than $10 then the answer is B231.  If B232 is greater than $10 then the answer is B232.  If either B231 or both are greater than $10 then I need the answer to be the higher of the 2.  I can't figure this out for anything.  I began writing the script but cannot figure out where to go from here.  Hopefully this make sense to someone! 

var theField = this.getField("B231");

var theValue = theField.value;

var theField2 = this.getField("B232");

var theValue2 = theField2.value;

if (theValue <= 10) {

    this.getField("B233").value= 0;

}

else {

     this.getField("B233").value= ();  

}

TOPICS
Acrobat SDK and JavaScript , Windows
735
Translate
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

correct answers 1 Correct answer

Community Expert , Oct 04, 2018 Oct 04, 2018

Use this code:

var field1 = this.getField("B231");

var value1 = Number(field1.valueAsString);

var field2 = this.getField("B232");

var value2 = Number(field2.valueAsString);

if (value1<=10 && value2<=10) event.value = 0;

else event.value = Math.max(value1, value2);

Translate
Community Expert ,
Oct 04, 2018 Oct 04, 2018

Use this code:

var field1 = this.getField("B231");

var value1 = Number(field1.valueAsString);

var field2 = this.getField("B232");

var value2 = Number(field2.valueAsString);

if (value1<=10 && value2<=10) event.value = 0;

else event.value = Math.max(value1, value2);

Translate
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
Participant ,
Oct 05, 2018 Oct 05, 2018

CORRECT ANSWER!  THANK YOU SO MUCH!!!! 

Translate
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
Participant ,
Oct 09, 2018 Oct 09, 2018

I encountered another issue with this that I didn't anticipate.  First of all, the solution was AWESOME.  The only other criteria that I didn't realize is if value2 should show as a negative number if it is greater than or equal to 0.  The value is correct for both Value and Value2.  Just want the result to be a negative number if value2 ends up being the result.  THANK YOU so much for your help with this.

var field1 = this.getField("B231");

var value1 = Number(field1.valueAsString);

var field2 = this.getField("B232");

var value2 = Number(field2.valueAsString);

if (value1<=10 && value2<=10) event.value = 0;

else event.value = Math.max(value1, value2);

Translate
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 ,
Oct 11, 2018 Oct 11, 2018

What should happen if both values are the same, then? Should the result be positive or negative?

Translate
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
Participant ,
Oct 11, 2018 Oct 11, 2018

Great question!  if both values are the same the result should be 0.  thevalue will always be a positive number.   Thevalue2 will always be a number that must be subtracted from thevalue.  For example:  thevalue2 could be a summation of numbers:  1+102+4=107.  107 now must be subtracted from thevalue.  Hope this makes sense.

Translate
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 ,
Oct 11, 2018 Oct 11, 2018

I'm not 100% sure I follow, but try this:

if (value1<=10 && value2<=10) event.value = 0;

else if (value1>value2) event.value = value1;

else if (value1<value2) event.value = value2*-1;

else if (value1==value2) event.value = 0;

Translate
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
Participant ,
Oct 18, 2018 Oct 18, 2018

PERFECT!!  Thank you so much for your assistance!

Translate
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
Participant ,
Oct 18, 2018 Oct 18, 2018

CORRECT

Translate
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
Participant ,
Oct 18, 2018 Oct 18, 2018

Good Afternoon,

First of all, you've been awesome in helping me with the code on my form.  I feel like once an issue gets resolved I encounter another one.  Same form, different area on the form.  I keep getting an error "the value entered doesn't match the format of the field".  I've tried but cannot not figure out how to resolve this issue.  The scenario involves a % issue.  I have 3 separate lines that have a % as a result for answer.  The results are considered:  Step 1 ("F7"), Step 2 ("F10") and Step 3 ("F13").  If Step 1 has a result that a percentage will appear.  If step 1 is not used then the answer will appear as 0%.  Same goes for Step 2 and Step 3.  Step 4 ("F14") and this is Step 1 + Step 2 + Step 3.  So, if the result was 1000% then the result would be 3000%.  Step 5 ("F15") is Step 4 / the number of steps is used.  So, if Step 1 is the only the divisor is 1, If Step 1 and Step 2 are used then the divisor is 2.  and If Step 1, Step 2 and Step 3 are used then the divisor is 3.  If no steps are used then the divisor is 0.  The other issue is if the percentage is greater than 100% then the result is 100%.  If if is less than 100% then the result is the average or 0.  Here is the code I've written so far which gives me a result but errors out as with the value entered doesn't match the format of the field.  F1000 will give a value of 1 if step 1 is used, F1001 will give a value of 1 if step 2 is used and F1002 will give a value of 1 if Step 3 is used.  F14 is the percentage values added up for Step 1, Step 2 and Step 3. 

var theField = this.getField("F1000");

var theValue = theField.value;

var theField2 = this.getField("F1001");

var theValue2 = theField2.value;

var theField3 = this.getField("F1002");

var theValue3 = theField3.value;

var theField4 = this.getField("F14");

var theValue4 = theField4.value;

if (theValue+theValue2+theValue3  < .000001) {

    this.getField("F15").value= theValue4 / (theValue + theValue2 + theValue3);

}

else {

     this.getField("F15").value=1;  

}

Translate
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
Participant ,
Oct 19, 2018 Oct 19, 2018
LATEST

You would be proud of me.  I figured it out and if it weren't for your previous feedback I would not have been able to do it.  THANK YOU!

Translate
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