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

Trying to retrieve content from a text field & use it in a conditional

MrDavo69
Registered: Jun 21 2010
Posts: 4

Hi Everyone,

I have a form with a text field and a button. The text field is called "orderNo", and the button is called "genOrder".

Initially the text field is empty, and clicking on the button fills the text field with an appropriate order number.

I need to check the text field for data (content) before writing the order number to it, this way if an order number is already present in the text field it will not be over written.

My intention is to use an if / else structure to perform the testing, however I don't know how to retrieve the content of the text field (if content is present!).

If anybody can suggest how I can go about retrieving the content of the text field and then using it in an if / else statement it will be greatly appreciated.

Kind Regards,

Davo

My Product Information:
Acrobat Pro 8.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
currentOrderNo = this.getField("orderNo").value;if (currentOrderNo==null || currentOrderNo=="") {// the field is empty, fill it with a new value} else {// the field is not empty, do something else}

(same code posted on the Adobe Forums)

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

MrDavo69
Registered: Jun 21 2010
Posts: 4
Hi try67,

Thanks very much for your response. Your a God send. :)

It turns out that I was on the right track before I posted this question, as I had the correct syntax for retrieving the value from the "orderNo" text field.

However I didn't fully understand how to use the information in a conditional statement, as I wasn't sure whether the return value was a string or an object. Either way your code takes care of all possible scenarios.

I have entered the following code into my document:
console.show(); var currentDate = new Date();var dateString = currentDate.getTime();currentOrderNo = this.getField("orderNo").value; if (currentOrderNo==null || currentOrderNo==""){alert("no order number");}else{alert("order number already exists!");}

Unfortunately as before when I run the script nothing seems to happen. I have enabled the console and below is the output that I am seeing:
[i]
Acrobat Database Connectivity Built-in Functions Version 8.0
Acrobat EScript Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
Acrobat Multimedia Version 8.0
Acrobat SOAP 8.0

alert is not defined
7:Field:Mouse Up
alert is not defined
7:Field:Mouse Up
alert is not defined
7:Field:Mouse Up
alert is not defined
7:Field:Mouse Up
syntax error
14:
alert is not defined
7:Field:Mouse Up
alert is not defined
7:Field:Mouse Up
alert is not defined
7:Field:Mouse Up
alert is not defined
7:Field:Mouse Up
alert is not defined
7:Field:Mouse Up
alert is not defined
9:Field:Mouse Up
[/i]

If you have any further suggestions they will be greatly appreciated.

Thanks

Davo
try67
Expert
Registered: Oct 30 2008
Posts: 2398
It's app.alert, not just alert.

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

MrDavo69
Registered: Jun 21 2010
Posts: 4
try67,

Once more you come through with the goods.

Your a champion. :)

Thanks again...

Cheers

Davo