Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Simple javascript problem using 'if' and '&&'

Avatar

Former Community Member
Could anyone please explain why my IF statement is not executed as being true



xfa.host.messageBox("tf_Company.rawValue: " + tf_Company.rawValue, "Debugging", 3);

xfa.host.messageBox("tf_Type.rawValue: " + tf_Type.rawValue, "Debugging", 3);



// At this point tf_Company is Integral and

// tf_Type is Modification

// However, the 'if' statement fails and does not display

// "In the IF Statement"

// The "After" is displayed.



if (tf_Type.rawValue == "Modification" && tf_Company.rawValue == "Integral")

{

xfa.host.messageBox("In the IF statement", "Debugging", 3);

tf_Company.rawValue = "TBA";

};



xfa.host.messageBox("After", "Debugging", 3);
3 Replies

Avatar

Level 4
If there is any difference in whitespace, the == operation won't match the strings.



One way you can spot if there is a whitespace difference is by putting some recognisable characters directly before and after the values in your debug box:



> xfa.host.messageBox("tf_Company.rawValue: >>" + tf_Company.rawValue + "<<", "Debugging", 3);



Might not be the cause in this case, but worth eliminating as a possibility.



Also, I think == is case sensitive, does the case match with what is shown in the debug box?

Avatar

Level 5
You might try testing each condition within parenthesis:



if ((tf_Type.rawValue == "Modification") && (tf_Company.rawValue == "Integral"))

Avatar

Former Community Member
Thank your for your help.



Yes, there was 1 space before the word "Integral".

I had never noticed. This has led me to look at other fields in the form and they all start 1 space in.



However, in another form that I have developed, there is no 1 space before the text when I enter text into a Text Field.



Would you know the reason for the 1 space before the text and how I eliminate it.