9 Replies Latest reply on Jun 17, 2013 6:10 AM by yeungyam

# Convert Feet and Inch to cm (and vice versa)

I need some help with conversion of height. The form was designed by the department and there is a field where one need to enter the height of the participant.

The height can either be in cm or in Feet + Inches (not just inches). Once a value has been entered in cm, it converts it automatically to feet and inches. If the user enter the height in feet and inches, it converts it immediately into cm. Much like the kg to lbs conversion fields in the attached document. I have been able to convert the height in cm into Feet and inches e.g. 165 cm = 5'5". However I am not sure how to do the opposite.

The problem is the way it has been designed as there is a box for Feet and another box for Inches. If the other measure was in Inches only, it would have been easier and that would be like the kg to lbs conversion.

I have tried multiple way to try to the conversion, but none would do it exactely like the kg to lbs conversion.

Here is the form:

https://workspaces.acrobat.com/?d=j8kksFor3eVIg6M07CdkmA

• ###### 1. Re: Convert Feet and Inch to cm (and vice versa)

I think you already have inches so you want feet and inches?

First get the feet. That's easy, divide by 12, and round down.

Now what are the inches? That turns out to be easier: get those feet and turn them back to inches, work out the difference.

Example:

66 inches

66 / 12 = 5.5

round down, that's 5 feet

Now turn those 5 feet back to inches, that's 60.

So, of our 66 inches, 60 are taken care of, and so we are left with 6.

5 foot 6 inches.

• ###### 2. Re: Convert Feet and Inch to cm (and vice versa)

That is correct. I want feet and inches, not just inches. What I need is to do the opposite. 5 feet, 5 inches = 165cm

• ###### 3. Re: Convert Feet and Inch to cm (and vice versa)

Yes. Now you know how it's done you just have to write the code. I hope you aren't wanting us to do your job for you!

• ###### 4. Re: Convert Feet and Inch to cm (and vice versa)

Have you even looked at my form?

• ###### 5. Re: Convert Feet and Inch to cm (and vice versa)

Well, I have now. What is your question, I thought I understood it but I obviously don't?

There doesn't seem to be any code to do this reverse conversion in the file.

• ###### 6. Re: Convert Feet and Inch to cm (and vice versa)

I tried the following code, but obviously does not work. The problem reside in the fact that I have to reunite 2 fields to get the height in cm and am not sure how to handle that.

var v1 = (function () {

var f_source = getField("Feet");

var result;

if (event.source && event.source === f_source) {

result = f_source * 30.48  ;

event.value = result == 0 ? "" : util.printf("%.0f", result);

}

})();

var v2 = (function () {

var f_source = getField("Inches");

var result;

if (event.source && event.source === f_source) {

result = +f_source  * 2.54 ;

event.value = result == 0 ? "" : util.printf("%.0f", result);

}

})();

event.value = v1 + v2;

• ###### 7. Re: Convert Feet and Inch to cm (and vice versa)

Where did you put this script?

As a matter of interest, how do you come to use this elaborate method of definining them immediately calling a function. I can see how it is supposed to work, but I don't see the point of it. And what is the test of event.source for? Is there a reference or recommendation you are following?

• ###### 8. Re: Convert Feet and Inch to cm (and vice versa)

I can answer some of that. You can use anonymous functions in JavaScript as a way to limit the scope of the variables declared within the function block. Otherwise the variables will have document global scope and persist as long as the document is loaded. What doesn't make sense is:

var v1 = (function () {

It should simply be:

(function () {

The test for event.source simple prevents an exception from being generated when during design time. It's not needed at design time.

• ###### 9. Re: Convert Feet and Inch to cm (and vice versa)

But how do you sum up the Feet and Inches variables?