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

Javascript with if then with an and/or

Guest
Aug 25, 2022 Aug 25, 2022

Hello,

 

I'm working on an error check that looking at "S3 Breakfast meal count" and if it is greater than 0 then I need it to look at the other two and if either one of those is greater than 0 (or both are) its okay and doesn’t return my error code.  However, if S3 Breakfast Meal count is greater than 0 and the other two are not greater than 0 two I need my error to return.

Here’s my code to date…

 

if (this.getField("*S3 B Meal Count").value >0 && this.getField (("S3 Add <= Count").value >0) or (this.getField ("S3 Add > Count").value >0)) event.value = "";

else event.value = "Add meal count for additional amount for lunch.";

 

Part of the above works…

               

For the or I’ve tried && and ||.  The || is only looking at the last half if its true it removes my code.  I tried doing a var script, but I couldn’t work that one out in my head. 

 

And yes, I know my field names stink, but I didn’t know anything about JavaScript when I developed my field name schema for this form (two years ago).  

 

I think I'm close with my code.

 

Any help is apprecaited.  

TOPICS
Acrobat SDK and JavaScript
768
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 ,
Aug 25, 2022 Aug 25, 2022

Try this:

if (this.getField("*S3 B Meal Count").value >0 && (this.getField ("S3 Add <= Count").value >0 || this.getField ("S3 Add > Count").value >0)) event.value = "";

else event.value = "Add meal count for additional amount for lunch.";

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
Guest
Aug 26, 2022 Aug 26, 2022

thanks...I'm closer...the issue now is that the else is appear if "*S3 B Meal Count" is 0. 

if (this.getField ("*S3 B Meal Count").value > 0 && (this.getField ("S3 Add <= Count").value >0 || this.getField ("S3 Add > Count").value >0)) event.value = ""; 
else event.value = "Add meal count for additional amount for lunch.";

 Would a var solve the problem...

var EC10 = this.getField ("*S3 B Meal Count").value;
if EC10 > 0 && (this.getField ("S3 Add <= Count").value >0 || this.getField ("S3 Add > Count").value >0)) event.value = ""; 
else event.value = "Add meal count for additional amount for lunch.";

But there is an error in that...

 

Again, I'm learning by trial and error. 

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 ,
Aug 26, 2022 Aug 26, 2022

May be that "*S3 B Meal Count" is not exact 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
Guest
Aug 26, 2022 Aug 26, 2022

clueless..what does that look like

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 ,
Aug 26, 2022 Aug 26, 2022

There's no difference between applying a value to a var or examining it directly.

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
Guest
Aug 26, 2022 Aug 26, 2022
LATEST

thanks

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