Copy link to clipboard
Copied
Hy everyone!
I have two text fields and also a button to check the input of the text fields.
I created a script that checks if the two fields are empty
if ((textXX == "") && (textYY == ""));
I also need to create a script that checks if ONE text field is empty and the OTHER
is wrong, and vice-versa. And this is where my problems begin.
If I write:
if ((textXX !== "Answer1") && (textYY == "")
Javascript will understand that (textXX " !== "Answer1") is equal to (textXX !== "")
So, how can I make my javascript read that an empty text field is not the same as a wrong text field?
I hope I have made myself crystal clear.
Thanks a lot for your reply!!
Copy link to clipboard
Copied
Correction:
Javascript will understand that (textXX !== "Answer1") is equal to (textXX == "").
Copy link to clipboard
Copied
You can use following condition:
textXX !== "Answer1" && textXX != ""
Copy link to clipboard
Copied
Thanks, but it is not working. Let ,e explin in more details
Part of the script is as follows:
if ((answer1 == "") && (answer2 == "")) {
app.alert ("The two fields are empty.", 1,0);
}
else if ((answer1 == "") && (answer2 !== "got")) {
app.alert ("1. The first field is empty.\n\n2. The answer in the second field is incorrect.", 1,0);
}
if ((answer1 !== "have") && (answer2 == "")) {
app.alert ("1. The answer of the first field is incorrect.\n\n2. The second field is empty.", 1,0);
}
I want my Javascript to understand that there is one filed that is incorrect and AT THE SAME TIME there is
one filed that is empty.
Thanks for your help.
Copy link to clipboard
Copied
The code you posted will do that. The only thing it's missing is "else" before the last if-statement.
If you don't add that then you will get two error messages when both fields are empty.
Copy link to clipboard
Copied
Now it is working beautifully. Thanks!!
Copy link to clipboard
Copied
Of course, it's also missing a condition that checks whether both answers are wrong.
Add that at the end, and make sure to include an "else" before it.
Copy link to clipboard
Copied
Yes, I did that, and I already have the script to check whether both conditions are wrong. I only didn´t think it was necessary to post it. Thanks a lot!