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

default value of text field

kmay
Registered: Mar 18 2010
Posts: 18

Hi All

I have a form that has two combo boxes:

TITLE
CURRENCY

Depending on the selection of CURRENCY depends on what bank details are displayed in Text field BANK DETAILS' however if TITLE is set to 'Commercial Invoice' I want the Text field BANK DETAILS to be blank, but fillable in by the user with other information..

my code so far for the BANK DETAILS field is:

if (this.getField("Currency").value == "USD $" ){ 
event.value = "Bank details 1.";  
}; 
if (this.getField("Currency").value == "GBP £"){ 
event.value = "bank details 2.";
}; 
if (this.getField("Currency").value == "EUR €"){ 
event.value = "bank details 3.";
};
 
if (this.getField("Title").value == "Commercial Invoice")
{
    event.value='';
};

however obviously I don't want the value of BANK DETAILS to be set to nothing because when the user types in the blank text box, the text just disappears.. Is there a way to say it should be the default value but can also be written in?

thanks

My Product Information:
Acrobat Pro Extended 9.3.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Where is this code? Is it in a calculation script?


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

kmay
Registered: Mar 18 2010
Posts: 18
yes, apologies for not being clearer - it's just a custom calculation
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Since the value of the Bank Details field is set from more than one place a calculation script is a reasonable choice. Unfortunately, this also complicates manual entry. So here's what you do:

1. Make this an "if/else if" block. Place the "Title" value as the first test. The title value overrides everything else and if it is selected then no other condition should be setting the value.
2. Add code to turn "readOnly" on and off for each of the times.
3. Add "event.rc=false" to the first condition, where "Title" == "Commercial Invoice". This will disable the calculation result. You'll need a condition that allows the script to determine when the switch was made for the first time so it can clear the field the first time the code is run with "Commercial Invoice", but allow user entry there after.

Something like this
if (this.getField("Title").value == "Commercial Invoice"){// use ReadOnly to determine transition stateif(event.target.readonly)event.value='';elseevent.rc = false; event.target.readonly = false;}else if (this.getField("Currency").value == "EUR €"){event.value = "bank details 3.";event.target.readonly = true;}

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script