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

Another Javascript problem - Multiple answers from different source fields

New Here ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

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

Views

408

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

correct answers 1 Correct answer

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

Votes

Translate

Translate
Community Expert ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

Sorry I made a mistake 🙂

try now :

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

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

Copy link to clipboard

Copied

LATEST

Thank you so much for your help.

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