Skip to main content
Participating Frequently
November 6, 2023
Answered

Check if text box is empty returns false

  • November 6, 2023
  • 3 replies
  • 1116 views

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.

This topic has been closed for replies.
Correct answer JR Boulay

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

 

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

 

 

 

 

3 replies

JR Boulay
Community Expert
Community Expert
November 6, 2023

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

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
November 6, 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
Participating Frequently
November 6, 2023

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

Participating Frequently
November 6, 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?