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

Check if text box is empty returns false

Community Beginner ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

I have 3 fields, let's call them T1, T2, T3. If T1 is filled/used, then I want T2 and T3 to be read only. But if the content of T1 is deleted again, then I want T2 and T3 to be editable again.

 

For T1, I implemented the following code in the OnBlur action:

var t1 = this.getField("T1").value;
if (!(t1 = "")) {
	this.getField("T2").readonly = true;
	this.getField("T3").readonly = true;
} else {
	this.getField("T2").readonly = false;
	this.getField("T3").readonly = false;
}

 

The problem I'm noticing is, that as soon as I fill text into T1 and then delete it afterwards, the script still treats it as if there is some content in T1. So, I guess there is some sort of special hidden character in there that I need to do a check for. Any ideas?

I also already tried to use valueAsString, just in case this would remove complications, but it doesn't.

TOPICS
JavaScript , PDF , PDF forms

Views

402

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 , Nov 06, 2023 Nov 06, 2023

Because in an if condition, equality is noted with a double equal sign.
You would have to write this:

 

if (!(t1 == "")) {

 

 

 

 

Votes

Translate

Translate
Community Beginner ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

I just found the work around that I can use t1.length > 0 to check if it contains content, but does anyone know why !(t1 = "") doesn't work?

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 ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

Because in an if condition, equality is noted with a double equal sign.
You would have to write this:

 

if (!(t1 == "")) {

 

 

 

 

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 Beginner ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

oh boy... sad that I overlook that. Thanks for the hint 🙂

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 ,
Nov 06, 2023 Nov 06, 2023

Copy link to clipboard

Copied

LATEST

Search for "JavaScript Comparison Operators" on this page: https://www.w3schools.com/js/js_operators.asp

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