Skip to main content
Inspiring
August 14, 2021
Question

How to make a difference between a null text field input and a wrong text field input?

  • August 14, 2021
  • 2 replies
  • 1161 views

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!!

 

This topic has been closed for replies.

2 replies

Bernd Alheit
Community Expert
Community Expert
August 14, 2021

You can use following condition:

textXX !== "Answer1" && textXX != ""

Inspiring
August 14, 2021

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.

try67
Community Expert
Community Expert
August 14, 2021

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.

Inspiring
August 14, 2021

Correction:

 

Javascript will understand that  (textXX !== "Answer1") is equal to (textXX == "").