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

Check if text box is empty returns false

Community Beginner ,
Nov 06, 2023 Nov 06, 2023

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
1.1K
Translate
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
1 ACCEPTED SOLUTION
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 == "")) {

 

 

 

 


Acrobate du PDF, InDesigner et Photoshopographe

View solution in original post

Translate
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

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?

Translate
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

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

 

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

 

 

 

 


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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

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

Translate
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
LATEST

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


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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