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

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

Participant ,
Aug 14, 2021 Aug 14, 2021

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

 

TOPICS
Create PDFs , JavaScript , PDF forms

Views

662

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
Participant ,
Aug 14, 2021 Aug 14, 2021

Copy link to clipboard

Copied

Correction:

 

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

 

 

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 ,
Aug 14, 2021 Aug 14, 2021

Copy link to clipboard

Copied

You can use following condition:

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

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
Participant ,
Aug 14, 2021 Aug 14, 2021

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.

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 ,
Aug 14, 2021 Aug 14, 2021

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.

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
Participant ,
Aug 14, 2021 Aug 14, 2021

Copy link to clipboard

Copied

Now it is working beautifully. Thanks!!

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 ,
Aug 14, 2021 Aug 14, 2021

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.

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
Participant ,
Aug 14, 2021 Aug 14, 2021

Copy link to clipboard

Copied

LATEST

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!

 

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