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.
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.
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.
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