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

Javascript with if then with an and/or

Community Beginner ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

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

Views

68

Likes

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

Copy link to clipboard

Copied

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.";

Likes

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

Copy link to clipboard

Copied

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. 

Likes

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

Copy link to clipboard

Copied

May be that "*S3 B Meal Count" is not exact 0.

Likes

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

Copy link to clipboard

Copied

clueless..what does that look like

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

LATEST

thanks

Likes

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