Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Distance conversion into feet and inches

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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    <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.
    Last edited by Philip M; 06-19-2008 at 02:32 PM. Reason: typo

  • #3
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am still receiving an error message (missing } in XML expression). Can you look at my attachment and give me a suggestion?

    Thanks!
    Attached Files Attached Files

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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?
    Last edited by Philip M; 06-19-2008 at 05:56 PM.

  • #7
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Javascripts can only function as part of an .html file.

    In other words, a javaScript can only be interpreted by a browser.
    Last edited by Philip M; 06-19-2008 at 07:09 PM.

  • #9
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess I'm out of luck unless someone else issues a different approach to my question. Thanks again for all your help!

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by Philip M View Post
    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

    anyways, perhaps this will get you started:

    Code:
    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")
    Last edited by rnd me; 06-19-2008 at 09:53 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by rnd me View Post
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •