PDA

View Full Version : Distance conversion into feet and inches



usdaeng
Jun 19th, 2008, 02:29 PM
I have created a pdf fillable form with embedded (javascript)distance computations. I want to convert my output product, (example 137.42 ft) into feet - inches (example: 137'-5"). Is there a javascript to do this conversion?

Thanks!!!

Philip M
Jun 19th, 2008, 02:49 PM
<script type="text/javascript">
x = "137.42"; // x is a string value - must have a decimal point
if (!/\./.test(x)) {
x = x + ".00"; // if no decimal point append .00
}
y = x.split(".");
len = y[1].length; // decimal places in initial value
p = Math.pow(10,len);
z = y[1]*12/p;
z = Math.round(z); // if required. to round to nearest inch
k = y[0] + " feet " + z + " inches";
alert (k);
</script>



BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.

usdaeng
Jun 19th, 2008, 04:48 PM
I am still receiving an error message (missing } in XML expression). Can you look at my attachment and give me a suggestion?

Thanks!

Philip M
Jun 19th, 2008, 06:18 PM
No, sorry. My paranoia prevents me from opening attachments posted by newcomers to the forum.

There is no missing } in the script I gave you.

usdaeng
Jun 19th, 2008, 06:38 PM
I understand. I will place my code first and error message below:

<script type="text/javascript">
x = "137.42";
if (!/\./.test(x))
{
x = x + ".00";
}
y = x.split(".");
len = y[1].length;
p = Math.pow(10,len);
z = y[1]*12/p;
z = Math.round(z);
k = y[0] + " feet " + z + " inches";
alert (k);
</script>

Error message I am receiving says:
missing } in XML expression
5: at line 6

Please!

Philip M
Jun 19th, 2008, 06:53 PM
Well, it works just fine for me. (IE6)
I don't see any reason why it does not work with XML or another browser.

I would look for a non-matched { somewhere else. Or have you wrapped it in a function with no closing } tag?

usdaeng
Jun 19th, 2008, 07:38 PM
Still not working on my end. I am using Acrobat Professional 8.1.2. The script I posted above is a stand-alone script (no other associated coding with that particular cell field).

Am I missing something or is it possibly an Acrobat issue?

Please

Philip M
Jun 19th, 2008, 08:06 PM
Javascripts can only function as part of an .html file.

In other words, a javaScript can only be interpreted by a browser.

usdaeng
Jun 19th, 2008, 08:19 PM
I guess I'm out of luck unless someone else issues a different approach to my question. Thanks again for all your help!

rnd me
Jun 19th, 2008, 10:42 PM
Javascripts can only function as part of an .html file.

In other words, a javaScript can only be interpreted by a browser.

i beg to differ Uses_outside_web_pages (http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pages)

anyways, perhaps this will get you started:



function cu (n, s, e) { //convert units
LengthOb= ({inch:12, inches:12, foot:1, feet:1});
return (n* LengthOb[e]) / LengthOb[s];}



cu(0.42, "feet" , "inches")

Philip M
Jun 20th, 2008, 08:49 AM
i beg to differ

You tell me something, but Acrobat does not seem to want to run the simple script I provided. I have no idea why!