These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Display alert if text field is blank

rbr00x
Registered: Oct 14 2009
Posts: 26
Answered

This is my script (using Acrobat Professional 9.2)
-------------------------------
 
If (this.getField("bene1_name").value==null)
{
app.alert("You have not entered a name for the beneficiary in Section 10. Please note, Section 10 is required. Be sure to fill in the beneficiary information before you submit the application. If you have questions, please call xxx-xxxx.", 3, 0, "Form Completion Instructions");
}
 
------------------------------------
 
I have added that script to the print button but nothing happens when I click the button. Not sure what I did wrong - is it the value?

My Product Information:
Acrobat Pro 9.2, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Are you getting any error listing in the JavaScript debugging console?

Make sure you are spelling and capitalizing everything properly.

Are you sure a null string is the same as null?

Try the following script:

console.clear();
console.println('null == "": ' + (null === ""))
try {

If (this.getField("bene1_name").value == "")
{
app.alert("You have not entered a name for the beneficiary in Section 10. Please note, Section 10 is required. Be sure to fill in the beneficiary information before you submit the application. If you have questions, please call xxx-xxxx.", 3, 0, "Form Completion Instructions");
}

} catch(e) { console.println(e.toString()); }

George Kaiser

rbr00x
Registered: Oct 14 2009
Posts: 26
The debugger says...

If is not defined
1:Field:Mouse Up
If is not defined
1:Field:Mouse Up
missing ) in parenthetical
1:
missing ) in parenthetical
1:
missing ) in parenthetical
1:
If is not defined
2:Field:Mouse Up
If is not defined
2:Field:Mouse Up
missing ) after argument list
2:
missing ) after argument list
3:
If is not defined
1:Field:Mouse Up
If is not defined
1:Field:Mouse Up
If is not defined
1:Field:Mouse Up
missing ) after argument list
2:
If is not defined
1:Field:Mouse Up
If is not defined
1:Field:Mouse Up
If is not defined
1:Field:Mouse Up
missing ) after argument list
3:
missing ) in parenthetical
1:
If is not defined
1:Field:Mouse Up
If is not defined
1:Field:Mouse Up
missing ; before statement
1:
missing ; before statement
1:
If is not defined
1:Field:Mouse Up
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Accepted Answer
When I cut and paste the script I get the following on the JS debugging console:

null == "": false

If is not defined
5:Field:Mouse UpReferenceError: If is not defined


So 'null' is not the same as a null string ("").

There is no 'If' statement in JavaScript, but there is an 'if' statement.

You also have some other syntax errors. But without seeing the code it is hard to specifically tell you what is wrong.

George Kaiser

rbr00x
Registered: Oct 14 2009
Posts: 26
Oh thank you. The capital I in If was the problem. I changed it to lower case and now it works. Thanks again!!
rbr00x
Registered: Oct 14 2009
Posts: 26
Well, I guess I was wrong. It displays the message whether the field is blank or not.
rbr00x
Registered: Oct 14 2009
Posts: 26
I had added a semi colon after the if and that was not correct. Here is my final working script...

if (this.getField("bene1_name").value=="")
{
app.alert("You have not entered a name for the beneficiary in Section 10. Section 10 is

required. Be sure to complete beneficiary information before submitting the application.

If you have questions please call xxx-xxxx.", 3, 0, "Form Completion Instructions");
}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
To be on the safe side, you can check for either null or the empty string, like so:

if (this.getField("bene1_name").value == null || this.getField("bene1_name").value == "") {

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com