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

Another Javascript problem - Multiple answers from different source fields

New Here ,
Feb 15, 2021 Feb 15, 2021

Completly new to this so any help would really be appriciated,

I have five text fields A1,A2,A3,A4,A5
A1 & A3 are free text for inputting numbers
A2 & A4 are the answers for A1 & A4 ("Pass" or "Fail")

 

var v = this.getField("A1").valueAsString;
if (v=="") event.value = "";
else {var score = Number(v);
if (score>=102 && score<=121) event.value = "Pass";
else if (score>=102) event.value = "Fail";
else if (score<=101) event.value = "Fail";}

This works perfectly after doing a lot of searching!

 

My problem is I would like A5 to give result if either A2 or A4 are "Fail" to show in A5 as "Report to SSM", the calculation below will give correct answer from A2 but not from A4

 

var A2 = (this.getField("A2").value);
var A4 = (this.getField("A4").value);

if (A2=="")

{event.value = "";}

else if(A2=="Pass")

{event.value= "";}

else if(A2== "Fail")

{event.value = "Report to SSM";}

else if (A4=="")

{event.value = "";}

else if(A4=="Pass")

{event.value= "";}

else if(A4== "Fail")

{event.value = "Report to SSM";}


Please help a newbie out

Cheers

TOPICS
JavaScript
796
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 15, 2021 Feb 15, 2021

Sorry I made a mistake 🙂

try now :

event.value = this.getField("A2").valueAsString == "Fail" || this.getField("A4").valueAsString == "Fail" ? "Report to SSM" : "";

View solution in original post

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 ,
Feb 15, 2021 Feb 15, 2021

Thats because your first line blocks "A4" part of code because that line will have advantage over "A4" code

if(A2 == "") event.value ="", will goes before A4 thats why field is empty.

try to use or method "||" like this:

event.value = this.getField("A2").valueAsString || this.getField("A4").valueAsString == "Fail" ? "Report to SSM" : "";

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
New Here ,
Feb 15, 2021 Feb 15, 2021

Thank you for the quick response, unfortunatly I now get "Report to SSM" with a Pass in A2?
Sorry if I havent explained properly but what I'm after is something like this: A2 & A4 "Pass" A5 will be blank, A2 "Pass", A4 "Fail", A5 "Report to SSM", A2 "Fail", A4 "Pass", A5 "Report to SSM", A2 & A4 "Fail", A5 "Report to SSM"
Thanks for helping

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 ,
Feb 15, 2021 Feb 15, 2021

Sorry I made a mistake 🙂

try now :

event.value = this.getField("A2").valueAsString == "Fail" || this.getField("A4").valueAsString == "Fail" ? "Report to SSM" : "";

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
New Here ,
Feb 15, 2021 Feb 15, 2021
LATEST

Thank you so much for your help.

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