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

validate event / unit conversion

EuroBum
Registered: Apr 9 2007
Posts: 6

Use validate event to convert imperial to metric for 2 text fields and vice versa.
 
I'm using Acrobat 7.0.5 .
 
Thanks.

My Product Information:
Acrobat Pro 7.0.5, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The validate event is the wrong place to do this. In fact it's much better to do conversions like this in one of two ways.

1. Two fields: Data entered into one field. Calculation event used on second field to convert input.

2. One field and two radio buttons. Radio buttons select for units. Data is always entered in the selected units. When the units change the field value is recalculated. This technique is great for the users, very intuitive. Place the conversion code into the mouse up action of the radio button. Handling conversion between two units is very simple, but 3 or more units is much more difficult. You have to keep an internal state variable that tracks the last unit so that you can tell what conversion needs to take place.

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

EuroBum
Registered: Apr 9 2007
Posts: 6
Thank you for your response. I have no problem with option #1. I might have to opt for option #2 but I would like let the user to input either way they want by specify like "10mm" or "10in" in the 1st field and the conversion will show on the 2nd field accordingly to the input i.e. "mm" or "in".
Thank you once again.
EuroBum
Registered: Apr 9 2007
Posts: 6
Hi Tom,

It's me again. I've made 2 radio buttons (export value = "in" and "mm").
I also created a custom format on another filed to reflect the unit change when user clicks on either button.

It works only when I actually change the value of the field i.e. first I click to select button "mm" then change the value 2 to 3 then it will display 3mm, no problem about that.

If I select the button "in" then 2 things happen:

1. It will not change from 3mm to 3in. I tried to use event.willCommit or event.change but it did not work. Maybe I did not code it correctly.
(When I click on the radio buttons, another field that have the script in "calculate" responds accordingly. Here's the code :
if (this.getField("Stat").value == "in") {
var m = this.getField("Text1i").value * 25.4 ;
event.value = m.toString().substr(0,5) + " mm";}
else {
var m = this.getField("Text1i").value / 25.4 ;
event.value = m.toString().substr(0,5) + " in";})

2. If I change the actual value 3 to 4 then it works fine but if I retype number 3 then nothing happens. It seems like I have to input value that differs than the old value (3) in the buffer then it will take it.

Here's the code in the custom format:

if (this.getField("Stat").value == "in") {
event.value = this.getField("Text1i").value + " in";}
else {
event.value = this.getField("Text1i").value + " mm";}

Please shine some light for me. Thanks.