/    Sign up×
Community /Pin to ProfileBookmark

A Script Challenge – I Think it Can be Done

I make miniatures, and many times I use full size plans as guides to make these miniatures, by converting the full size dimensions to a convenient scale dimension. Unfortunately it currently takes several steps and several calculators to do the job. [URL=http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml]Current Calculators[/URL]

I was wondering if it is possible to make a script calculator that would automatically (with options provided by the user) convert a full size dimension to the scale dimension, providing the answer in its simplest form – whether the user wants it in decimal, fractional, or metric measurements.

For example – I have a plan that requires slates for a chair that are 1/2″ x 1+1⁄2″ x 17+3⁄8″ (thickness, width, length in inches) and I need to convert them to 1:12 scale (1 inch = 1 foot) I have a friend that needs to convert to 1:6 scale (1 inch = 6 inches) and another friend that needs 1:24 scale (1 inch = 2 feet)

I currently use a calculator that converts to scale, providing answers in decimal form (in 1:12 scale) – 1/2″ x 1+1⁄2″ x 17+3⁄8″ would equal

0.041666666666666664” x 0.125” x 1.4479166666666667”

I then input into these answers into another calculator that converts to fractions (I provide the level of accuracy needed, i.e. the nearest 96th of an inch) thank you [B][COLOR=Red]tabzter[/COLOR][/B]

4/96” x 12/96” x 1+43/96”

Finally I convert these to their simplest form –

1/24” x 1/8” x 1+43/96”

Ideally I would like a calculator that could:

[list=1]

  • [*]

    Provide the Scale Needed (any numerical scale entered – saved until changed)


  • [*]

    Choose the Final Output in Simplest Form – i.e. Fraction, Decimal, Metric (selectable buttons that remain activated until changed)


  • [*]

    Provide the level of accuracy needed – i.e. the closest 1/8th in., 1/16th in., 1/96th in., or number of decimal points for the final solution, etc. (selectable buttons for fractions or #of decimal places – that remain activated until changed)


  • [*]

    Where I can put all three dimensions in at once – i.e. Thickness, Width, Length


  • [*]

    And with a push of a single button – get the final answer, without NaN showing up when a leading 0 is not provided.


  • [/list]

    I believe this is possible (especially with this group) but I haven’t been able to find a script like this anywhere – and I’ve searched for weeks.

    Any Help would be appreciated and both credit and links will be provided when placed on my web page.

    Thank You

    ArchAngle @ [URL=http://www.zooplies.com]Zooplies[/URL]

    to post a comment
    JavaScript

    8 Comments(s)

    Copy linkTweet thisAlerts:
    @cridleySep 14.2006 — The easiest thing would be to provide the 3 scripts you have, so they could be merged into one, rather than doing it from scratch.
    Copy linkTweet thisAlerts:
    @ArchAngleauthorSep 14.2006 — The two scripts that I use can be found on the [URL=http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml]Current Calculators[/URL] page. The Third is step is done in my head so I don't have a script - the two scripts I have are here:

    Scale Conversion Calculator:
    [CODE]<script>

    <!-- Activate Cloaking Device
    //***************************************************************************
    // This Javascript was adapted from
    // Formatting Money Values
    // by Tim Wallace ([email protected])
    //***************************************************************************

    function compute()
    {
    if (document.forms[0].inunit.value==document.forms[0].outunit.value) {
    var partA= eval(document.forms[0].input.value)/(document.forms[0].scale.value);
    document.forms[0].output.value=partA;

    } else {
    if (document.forms[0].inunit.value=="inches") {

    var partA= eval(document.forms[0].input.value)/(document.forms[0].scale.value);
    document.forms[0].output.value=partA*2.54;
    } else {
    var partA= eval(document.forms[0].input.value)/(document.forms[0].scale.value);
    document.forms[0].output.value=partA/2.54;
    }

    }
    }

    function unit1()
    {
    document.forms[0].inunit.value="centimeters";
    compute();

    }

    function unit2()
    {
    document.forms[0].inunit.value="inches";
    compute();

    }

    function unit3()
    {
    document.forms[0].outunit.value="centimeters";
    compute();

    }

    function unit4()
    {
    document.forms[0].outunit.value="inches";
    compute();

    }

    // Called by Reset button - sets original values.
    function resetIt()
    {
    document.forms[0].scale.value="6";
    document.forms[0].input.value="10";
    document.forms[0].output.value="";

    document.forms[0].inunit.value="inches";

    document.forms[0].outunit.value="inches";

    }

    // Called by About button - info on example.
    function about()
    {
    alert("nJavascript adapted by Jimbob 5/99 from "Formatting Money Values"n by Tim Wallace ([email protected]).n");
    }


    function computeb()
    {
    if (document.forms[0].inunitb.value==document.forms[0].outunitb.value) {
    var partAb= eval(document.forms[0].inputb.value)*(document.forms[0].scaleb.value);
    document.forms[0].outputb.value=partAb;

    } else {
    if (document.forms[0].inunitb.value=="inches") {

    var partAb= eval(document.forms[0].inputb.value)*(document.forms[0].scaleb.value);
    document.forms[0].outputb.value=partAb*2.54;
    } else {
    var partAb= eval(document.forms[0].inputb.value)*(document.forms[0].scaleb.value);
    document.forms[0].outputb.value=partAb/2.54;
    }

    }
    }

    function unit1b()
    {
    document.forms[0].inunitb.value="centimeters";
    computeb();

    }

    function unit2b()
    {
    document.forms[0].inunitb.value="inches";
    computeb();

    }

    function unit3b()
    {
    document.forms[0].outunitb.value="centimeters";
    computeb();

    }

    function unit4b()
    {
    document.forms[0].outunitb.value="inches";
    computeb();

    }


    function scaleupdown()
    {
    computeb();
    document.forms[0].inunit.value=document.forms[0].outunitb.value;
    document.forms[0].input.value= document.forms[0].outputb.value;
    compute();
    }

    // Deactivate Cloaking -->
    </script>[/CODE]

    Decimal to Fraction Script:
    [CODE]
    <script type="text/javascript">
    var primValue = document.getElementById("primary");
    var secValue = document.getElementById("secondary");
    document.getElementById("convert").onclick = function() {
    var answer = document.getElementById("answer");
    if (secValue.value == "") {
    answer.firstChild.data = "No Scale Factor Entered: Please Try Again";
    } else
    if (primValue.value.match(/^d*.?d*$/)) {
    var integer = parseInt(primValue.value.match(/^d*.?/)[0]);
    var decimal = parseFloat("0"+primValue.value.match(/.d*$/)[0]);
    var rationalise = Math.round(secValue.value*decimal);
    answer.innerHTML = integer+"<sup>"+rationalise+"</sup>/<sub>"+secValue.value+"</sub>";
    } else {
    answer.firstChild.data = "Wrong Number Format Entered: Please Try Again";
    }
    };
    </script>

    <div id="answer" style="border:2px solid green; font-family:courier new, arial; font-size:1.3em; height:40px; width:112px">

    Answer Here</div>[/CODE]
    Copy linkTweet thisAlerts:
    @cridleySep 15.2006 — Hi, I've made a start, see if this looks promising: (paste it into an empty .html file and open it)

    [code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <HTML><HEAD><TITLE>Scale Conversion Tool - Decimal to Fraction Tool</TITLE>

    <SCRIPT>

    <!--

    function Calculate(value, acc)
    {
    if (value.match(/^d*.?d*$/)) {
    var integer = parseInt(value.match(/^d*.?/)[0]);
    var decimal = parseFloat("0"+value.match(/.d*$/)[0]);
    var rationalise = Math.round(acc*decimal);
    return integer+"<sup>"+rationalise+"</sup>/<sub>"+acc+"</sub>";
    } else {
    return "Wrong Number Format Entered: Please Try Again";
    }
    }
    function frac()
    {
    var valuex = document.forms[0].outputx.value
    var valuey = document.forms[0].outputy.value
    var valuez = document.forms[0].outputz.value
    var acc = document.forms[0].accuracy.value

    var answerx = document.getElementById("answerx");
    var answery = document.getElementById("answery");
    var answerz = document.getElementById("answerz");
    if (acc == "")
    {
    alert("No Accuracy Entered: Please Try Again")
    }
    else
    {
    answerx.innerHTML = Calculate(valuex,acc)
    answery.innerHTML = Calculate(valuey,acc)
    answerz.innerHTML = Calculate(valuez,acc)
    }

    }
    function compute()
    {
    if (document.forms[0].inunit.value==document.forms[0].outunit.value)

    {
    var partA = eval(document.forms[0].inputx.value)/(document.forms[0].scale.value);
    document.forms[0].outputx.value=partA;

    partA = eval(document.forms[0].inputy.value)/(document.forms[0].scale.value);
    document.forms[0].outputy.value=partA;

    partA = eval(document.forms[0].inputz.value)/(document.forms[0].scale.value);
    document.forms[0].outputz.value=partA;

    }
    else
    {
    if (document.forms[0].inunit.value=="inches")

    {
    var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value)
    document.forms[0].outputx.value=partA*2.54
    partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
    document.forms[0].outputy.value=partA*2.54
    partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
    document.forms[0].outputz.value=partA*2.54
    }

    else
    {
    var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value
    )
    document.forms[0].outputx.value=partA/2.54
    partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
    document.forms[0].outputy.value=partA/2.54
    partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
    document.forms[0].outputz.value=partA/2.54
    }

    }
    frac()
    }

    function unit1()
    {
    document.forms[0].inunit.value="centimeters";
    compute();

    }

    function unit2()
    {
    document.forms[0].inunit.value="inches";
    compute();

    }

    function unit3()
    {
    document.forms[0].outunit.value="centimeters";
    compute();

    }

    function unit4()
    {
    document.forms[0].outunit.value="inches";
    compute();

    }

    // Called by Reset button - sets original values.
    function resetIt()
    {
    document.forms[0].scale.value="6";
    document.forms[0].input.value="10";
    document.forms[0].output.value="";

    document.forms[0].inunit.value="inches";

    document.forms[0].outunit.value="inches";

    }

    -->
    </SCRIPT>
    </FONT></P>
    <H2 class=producthdr align=center><FONT face=Verdana
    color=#2271a0 size=4>SCALE CONVERSION
    CALCULATOR<BR></FONT></H2>
    <FORM>
    <TABLE id=table10 cellPadding=3 width=619
    bgColor=#ffffff border=2>
    <TBODY>
    <TR>
    <TD align=middle><FONT
    face=Verdana><STRONG>Scale</STRONG> </FONT><br/>
    <FONT
    face=Verdana><STRONG>Accuracy</STRONG></FONT></TD>
    <TD align=middle colSpan=4><FONT
    face=Verdana><STRONG>1:</STRONG></FONT><INPUT
    size=10 value=12 name='scale'> <br/>
    &nbsp;&nbsp;&nbsp;
    <INPUT
    size=10 name='accuracy'> </TD>
    <TD align=left width=263 rowSpan=3>
    <CENTER><FONT face=Verdana><B>SCALE
    DOWN</B></FONT></CENTER><FONT
    face=Verdana><BR>&nbsp;</FONT>
    <UL>
    <LI>To enter the scaling factor; for 1/24th
    scale, enter a '24'; for 1/144th scale, enter a
    '144', for 1/12th scale enter a 12, (the
    default)
    <LI><FONT face=Verdana>In the box marked
    "input", enter the measurement of a real-world
    object in either inches or centimeters (see
    <B><A
    href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#frac">*below</A></B>
    for entering fractions) </FONT>
    <LI><FONT face=Verdana>Press the button labeled
    "in" (inches) or "cm" (centimeter) </FONT>
    <LI><FONT face=Verdana>The scaled down size of
    that object is displayed in the box marked
    "output" </FONT>
    <LI><FONT face=Verdana>Pressing the "in" or "cm"
    output button will cause the results to be
    recalculated and displayed in the unit of
    measure you've selected. </FONT></LI></UL></TD></TR>
    <TR>
    <TD align=middle><FONT
    face=Verdana><STRONG>Input</STRONG> </FONT></TD>
    <TD align=middle>
    x:
    <INPUT size=10 name=inputx>
    y: <INPUT size=10 name=inputy>
    z: <INPUT size=10 name=inputz>
    </TD>
    <TD align=middle><INPUT size=10 value=inches
    name=inunit> </TD>
    <TD align=middle><INPUT onclick=unit1() type=button value=cm>
    </TD>
    <TD align=middle><INPUT onclick=unit2() type=button value=in>
    </TD></TR>
    <TR>
    <TD align=middle><FONT
    face=Verdana><STRONG>Output</STRONG> </FONT></TD>
    <TD align=middle>
    x:
    <INPUT size=10 name=outputx><br/>
    <div id=answerx
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    y:
    <INPUT size=10 name=outputy><br/>
    <div id=answery
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    z:
    <INPUT size=10 name=outputz><br/>
    <div id=answerz
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    </TD>
    <TD align=middle><INPUT size=10 value=inches
    name=outunit> </TD>
    <TD align=middle><INPUT onclick=unit3() type=button value=cm>
    </TD>
    <TD align=middle><INPUT onclick=unit4() type=button value=in>
    </TD></TR></TBODY></TABLE><SPAN
    style="FONT-SIZE: 9pt"><BR><BR><B><A name=frac>*Entering
    Fractions:</A></B> If you want to find out the decimal
    inch for a fraction, simply enter a&nbsp; fraction,
    1/32, 1/2, 95/96 . If you input a mixed measure like
    "12-1/2" instead of "12.5", it evaluates the expression
    as "12 minus 1 divided by 2", the result of which is
    "11.5". Therefore, you can enter fractional inches if
    you input the value as <B>"12+1/2"</B> (using a
    "<B>plus</B>" instead of the "minus"). The expression
    will be evaluated as a decimal value. However, if you
    input the measure as "12 1/2" (without the "plus" or
    "minus" operator) you will cause a JavaScript error! You
    can however enter something like (5*12)+4+(3/4), which
    is like saying "five feet four and three-quarter inches"
    (5 feet times 12 inches plus 4 inches plus 3/4 of an
    inch).&nbsp; NOTE! The calculator doesn't under stand
    Feet - it requires it to be converted into inches, like
    above.&nbsp; The same would hold true for Meters and
    centimeters!</SPAN>
    <P class=producthdr>"*" = times (multiply),&nbsp;&nbsp;
    "/" = divide,&nbsp;&nbsp; "+" = plus,&nbsp;&nbsp; "-" =
    minus.</P></FORM></TD></TR></TBODY></TABLE>
    [/code]
    Copy linkTweet thisAlerts:
    @ArchAngleauthorSep 15.2006 — You've done a great job so far although I am getting an error when I enter 12 as the input when 12 is the scale. As well as any time the scale and input are the same - I get the error. On occasion after I get an error and just replace the number (highlight and replace) I will get same errors - maybe this is because the field isn't reset properly - I don't know, possibly a clear key would fix that?

    I knew this group would be the best bet on getting this type of calculator created.

    ArchAngle
    Copy linkTweet thisAlerts:
    @ArchAngleauthorSep 16.2006 — Wierd - I installed a copy of the script on the web site - and all of a sudden there are no errors - So the script is working well as far as it goes. Don't know why I had errors before, I can't duplicate them now. [URL=http://zooplies.com/Calculator_Page.shtml]The Page is Here[/URL]

    ArchAngle
    Copy linkTweet thisAlerts:
    @cridleySep 16.2006 — Hi, I'll probably finish this off on monday, and yes a few errors were to be expected as i never really tested it.
    Copy linkTweet thisAlerts:
    @ArchAngleauthorSep 21.2006 — So far you have done an excellent job with the script - I did make a few changes, cosmetic only but thought you would like the changed script so I've included a script below for you. The only thing remaining is to reduce the common fraction to their simplest form, and possibly a clear key.

    [CODE]<FORM>
    <div align="center"><TABLE id=table2 cellPadding=3 width=619
    bgColor=#ffffff border=2>
    <TBODY>
    <TR>
    <TD align=middle><FONT face=Verdana><font color="#FF0000"><STRONG>Scale</STRONG></font> <br>
    </FONT><br/>
    <FONT
    face=Verdana color="#FF0000"><STRONG>Accuracy</STRONG></FONT></TD>
    <TD align=middle colSpan=4>
    <FONT face=Verdana><STRONG><font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1:</font></STRONG></FONT><INPUT
    size=4 value=12 name='scale'><br>
    To Nearest &nbsp;<font size="3">=</font>&nbsp;
    <INPUT
    size=4 value="96 " name='accuracy' style="text-align: right"><sup>th </sup>
    inch</TD>
    <TD align=left width=263 rowSpan=3>
    <CENTER><FONT face=Verdana><B>SCALE
    DOWN</B></FONT></CENTER>
    <UL>
    <LI>To enter the scaling factor other than 1/12<sup>th</sup>,
    highlight the default 12 and enter whatever scale you want; 24 for 1/24th scale; 144 for 1/144th scale; etc..
    <LI>Next enter the level of accuracy you want.
    To the nearest 24<sup>th</sup> inch, 48<sup>th</sup>
    inch, etc.. (Read<b>
    <a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#Caution:">
    Caution</a></b>)<LI>In the boxes marked "<b><font color="#FF0000">input</font></b>&quot;,
    enter the measurement of a real-world object in
    either inches or centimeters (Read
    <a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#frac">
    <b>Fractions</b></a>)
    <LI>Press <INPUT onclick=unit2() type=button value=in> button
    for inches<br>
    &nbsp;or <INPUT onclick=unit1() type=button value=cm>
    button for centimeter
    <LI>The scaled size of
    that object is displayed in the boxes marked
    "<b><font color="#FF0000">output</font></b>"
    <LI>Your Answers will be displayed in both
    decimal
    and common&nbsp; fraction.</LI></UL></TD></TR>
    <TR>
    <TD align=middle><FONT
    face=Verdana><STRONG><font color="#FF0000">Input</font>
    in Inches, Centimeters or Millimeters only
    </STRONG> </FONT></TD>
    <TD align=middle>
    x: <INPUT size=10 name=inputx><br>
    y: <INPUT size=10 name=inputy><br>
    z: <INPUT size=10 name=inputz></TD>
    <TD align=middle><INPUT size=10 value=inches
    name=inunit> </TD>
    <TD align=middle><INPUT onclick=unit1() type=button value=cm>
    </TD>
    <TD align=middle><INPUT onclick=unit2() type=button value=in>
    </TD></TR>
    <TR>
    <TD align=middle><FONT face=Verdana><STRONG><font color="#FF0000">Output</font>
    in Decimal &amp; Common Fractions</STRONG> </FONT></TD>

    <TD align=middle>
    x:
    <INPUT size=10 name=outputx><br/>
    <div id=answerx
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    y:
    <INPUT size=10 name=outputy><br/>
    <div id=answery
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    z:
    <INPUT size=10 name=outputz><br/>
    <div id=answerz
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    </TD>
    <TD align=middle><INPUT size=10 value=inches
    name=outunit> </TD>

    <TD align=middle><INPUT onclick=unit3() type=button value=cm>
    </TD>
    <TD align=middle><INPUT onclick=unit4() type=button value=in>
    </TD></TR></TBODY></TABLE></div>
    <BR><BR><B><a name="frac">Fractions:</a></B> When
    entering numbers, make sure you're using only inches
    and/or fractions, and enter them in a form the computer
    will understands.&nbsp; i.e.&nbsp; If you input a mixed
    measure like &quot;<b>12-1/2</b>&quot; the computer will evaluate
    the expression as &quot;<b>12</b> minus <b>1</b> divided by
    <b>2</b>&quot;, the result of which is &quot;<b>11.5</b>&quot;. You
    must enter the expression the computer understands.&nbsp;
    i.e. <B>&quot;12+1/2&quot;</B> (using a &quot;<B>plus</B>&quot; instead of the &quot;minus&quot;) or as <b>12.5</b>&quot;.&nbsp;

    <SPAN
    style="font-weight:700">The same would hold true for
    centimeters and millimeters!</SPAN><br>
    <br>
    <b><font color="#FF0000">NEVER </font></b>input the
    measure as &quot;<b>12 1/2</b>&quot; (without the &quot;plus&quot; or
    &quot;minus&quot; operator) this will cause a JavaScript error!&nbsp;&nbsp;

    <font color="#FF0000"><b><br>
    <br>
    NOTE!</b></font> This calculator doesn't understand Feet
    or Meters - it requires them to be converted into
    inches/centimeters.&nbsp;&nbsp; You can however enter
    something like (5*12)+4+(3/4), which is like saying
    &quot;five feet four and three-quarter inches&quot; (5 feet times
    12 inches plus 4 inches plus 3/4 of an inch).&nbsp;
    Computer understands that &quot;*&quot; = multiply,&nbsp;&nbsp;
    &quot;/&quot; = divide,&nbsp;&nbsp; &quot;+&quot; = plus,&nbsp;&nbsp; &quot;-&quot; =
    minus.<b><br>

    <br>
    <a name="Caution:">Caution:</a></b>&nbsp; Entering a
    small level of accuracy can adversely affect your
    results - the computer will always round to the nearest
    scale factor.&nbsp; i.e. you enter a scale factor of 12,
    and an accuracy of 12.&nbsp; This means that you are
    only getting accuracy to the nearest inch for the scale
    model, which means that if you need an item 3+1/2 inches
    you'll get a scale result of 4/12 - which is really 4
    inches.&nbsp; The decimal fraction displayed will be
    correct and isn't affected by the accuracy level.</FORM></TD>
    &nbsp;<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <HTML><HEAD><TITLE>Scale Conversion Tool - Decimal to Fraction Tool</TITLE>

    <SCRIPT>

    <!--

    function Calculate(value, acc)
    {
    if (value.match(/^d*.?d*$/)) {
    var integer = parseInt(value.match(/^d*.?/)[0]);
    var decimal = parseFloat("0"+value.match(/.d*$/)[0]);
    var rationalise = Math.round(acc*decimal);
    return integer+"<sup>"+rationalise+"</sup>/<sub>"+acc+"</sub>";
    } else {
    return "Wrong Number Format Entered: Please Try Again";
    }
    }
    function frac()
    {
    var valuex = document.forms[0].outputx.value
    var valuey = document.forms[0].outputy.value
    var valuez = document.forms[0].outputz.value
    var acc = document.forms[0].accuracy.value

    var answerx = document.getElementById("answerx");
    var answery = document.getElementById("answery");
    var answerz = document.getElementById("answerz");
    if (acc == "")
    {
    alert("No Accuracy Entered: Please Try Again")
    }
    else
    {
    answerx.innerHTML = Calculate(valuex,acc)
    answery.innerHTML = Calculate(valuey,acc)
    answerz.innerHTML = Calculate(valuez,acc)
    }

    }
    function compute()
    {
    if (document.forms[0].inunit.value==document.forms[0].outunit.value)

    {
    var partA = eval(document.forms[0].inputx.value)/(document.forms[0].scale.value);
    document.forms[0].outputx.value=partA;

    partA = eval(document.forms[0].inputy.value)/(document.forms[0].scale.value);
    document.forms[0].outputy.value=partA;

    partA = eval(document.forms[0].inputz.value)/(document.forms[0].scale.value);
    document.forms[0].outputz.value=partA;

    }
    else
    {
    if (document.forms[0].inunit.value=="inches")

    {
    var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value)
    document.forms[0].outputx.value=partA*2.54
    partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
    document.forms[0].outputy.value=partA*2.54
    partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
    document.forms[0].outputz.value=partA*2.54
    }

    else
    {
    var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value
    )
    document.forms[0].outputx.value=partA/2.54
    partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
    document.forms[0].outputy.value=partA/2.54
    partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
    document.forms[0].outputz.value=partA/2.54
    }

    }
    frac()
    }

    function unit1()
    {
    document.forms[0].inunit.value="centimeters";
    compute();

    }

    function unit2()
    {
    document.forms[0].inunit.value="inches";
    compute();

    }

    function unit3()
    {
    document.forms[0].outunit.value="centimeters";
    compute();

    }

    function unit4()
    {
    document.forms[0].outunit.value="inches";
    compute();

    }

    // Called by Reset button - sets original values.
    function resetIt()
    {
    document.forms[0].scale.value="6";
    document.forms[0].input.value="10";
    document.forms[0].output.value="";

    document.forms[0].inunit.value="inches";

    document.forms[0].outunit.value="inches";

    }

    -->
    </SCRIPT>
    [/CODE]


    Thanks again for your excellent work

    ArchAngle
    Copy linkTweet thisAlerts:
    @cridleySep 21.2006 — Hi, give this a test:

    [code=html]
    <FORM>
    <div align="center"><TABLE id=table2 cellPadding=3 width=619
    bgColor=#ffffff border=2>
    <TBODY>
    <TR>
    <TD align=middle><FONT face=Verdana><font color="#FF0000"><STRONG>Scale</STRONG></font> <br>
    </FONT><br/>
    <FONT
    face=Verdana color="#FF0000"><STRONG>Accuracy</STRONG></FONT></TD>
    <TD align=middle colSpan=4>
    <FONT face=Verdana><STRONG><font size="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1:</font></STRONG></FONT><INPUT
    size=4 value=12 name='scale'><br>
    To Nearest &nbsp;<font size="3">=</font>&nbsp;
    <INPUT
    size=4 value="96 " name='accuracy' style="text-align: right"><sup>th </sup>
    inch</TD>
    <TD align=left width=263 rowSpan=3>
    <CENTER><FONT face=Verdana><B>SCALE
    DOWN</B></FONT></CENTER>
    <UL>
    <LI>To enter the scaling factor other than 1/12<sup>th</sup>,
    highlight the default 12 and enter whatever scale you want; 24 for 1/24th scale; 144 for 1/144th scale; etc..
    <LI>Next enter the level of accuracy you want.
    To the nearest 24<sup>th</sup> inch, 48<sup>th</sup>
    inch, etc.. (Read<b>
    <a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#Caution:">
    Caution</a></b>)<LI>In the boxes marked "<b><font color="#FF0000">input</font></b>&quot;,
    enter the measurement of a real-world object in
    either inches or centimeters (Read
    <a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#frac">
    <b>Fractions</b></a>)
    <LI>Press <INPUT onclick=unit2() type=button value=in> button
    for inches<br>
    &nbsp;or <INPUT onclick=unit1() type=button value=cm>
    button for centimeter
    <LI>The scaled size of
    that object is displayed in the boxes marked
    "<b><font color="#FF0000">output</font></b>"
    <LI>Your Answers will be displayed in both
    decimal
    and common&nbsp; fraction.</LI></UL></TD></TR>
    <TR>
    <TD align=middle><FONT
    face=Verdana><STRONG><font color="#FF0000">Input</font>
    in Inches, Centimeters or Millimeters only
    </STRONG> </FONT></TD>
    <TD align=middle>
    x: <INPUT size=10 name=inputx><br>
    y: <INPUT size=10 name=inputy><br>
    z: <INPUT size=10 name=inputz></TD>
    <TD align=middle><INPUT size=10 value=inches
    name=inunit> </TD>
    <TD align=middle><INPUT onclick=unit1() type=button value=cm>
    </TD>
    <TD align=middle><INPUT onclick=unit2() type=button value=in>
    </TD></TR>
    <TR>
    <TD align=middle><FONT face=Verdana><STRONG><font color="#FF0000">Output</font>
    in Decimal &amp; Common Fractions</STRONG> </FONT></TD>

    <TD align=middle>
    x:
    <INPUT size=10 name=outputx><br/>
    <div id=answerx
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    y:
    <INPUT size=10 name=outputy><br/>
    <div id=answery
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    z:
    <INPUT size=10 name=outputz><br/>
    <div id=answerz
    style="border:solid black 1px; width: 112px;height: 40px"></div>
    </TD>
    <TD align=middle><INPUT size=10 value=inches
    name=outunit> </TD>

    <TD align=middle><INPUT onclick=unit3() type=button value=cm>
    </TD>
    <TD align=middle><INPUT onclick=unit4() type=button value=in>
    </TD></TR></TBODY></TABLE></div>
    <BR><BR><B><a name="frac">Fractions:</a></B> When
    entering numbers, make sure you're using only inches
    and/or fractions, and enter them in a form the computer
    will understands.&nbsp; i.e.&nbsp; If you input a mixed
    measure like &quot;<b>12-1/2</b>&quot; the computer will evaluate
    the expression as &quot;<b>12</b> minus <b>1</b> divided by
    <b>2</b>&quot;, the result of which is &quot;<b>11.5</b>&quot;. You
    must enter the expression the computer understands.&nbsp;
    i.e. <B>&quot;12+1/2&quot;</B> (using a &quot;<B>plus</B>&quot; instead of the &quot;minus&quot;) or as

    <b>12.5</b>&quot;.&nbsp;

    <SPAN
    style="font-weight:700">The same would hold true for
    centimeters and millimeters!</SPAN><br>
    <br>
    <b><font color="#FF0000">NEVER </font></b>input the
    measure as &quot;<b>12 1/2</b>&quot; (without the &quot;plus&quot; or
    &quot;minus&quot; operator) this will cause a JavaScript error!&nbsp;&nbsp;

    <font color="#FF0000"><b><br>
    <br>
    NOTE!</b></font> This calculator doesn't understand Feet
    or Meters - it requires them to be converted into
    inches/centimeters.&nbsp;&nbsp; You can however enter
    something like (5*12)+4+(3/4), which is like saying
    &quot;five feet four and three-quarter inches&quot; (5 feet times
    12 inches plus 4 inches plus 3/4 of an inch).&nbsp;
    Computer understands that &quot;*&quot; = multiply,&nbsp;&nbsp;
    &quot;/&quot; = divide,&nbsp;&nbsp; &quot;+&quot; = plus,&nbsp;&nbsp; &quot;-&quot; =
    minus.<b><br>

    <br>
    <a name="Caution:">Caution:</a></b>&nbsp; Entering a
    small level of accuracy can adversely affect your
    results - the computer will always round to the nearest
    scale factor.&nbsp; i.e. you enter a scale factor of 12,
    and an accuracy of 12.&nbsp; This means that you are
    only getting accuracy to the nearest inch for the scale
    model, which means that if you need an item 3+1/2 inches
    you'll get a scale result of 4/12 - which is really 4
    inches.&nbsp; The decimal fraction displayed will be
    correct and isn't affected by the accuracy level.</FORM></TD>
    &nbsp;<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <HTML><HEAD><TITLE>Scale Conversion Tool - Decimal to Fraction Tool</TITLE>

    <SCRIPT>

    <!--

    function reduce(top,bot) {

    var factorX //highest common factor

    if ( top == 0 || bot == 0 ) {
    factorX=1;
    return "<sup>"+top+"</sup>/<sub>"+bot+"</sub>";
    }

    top = Math.abs( top );
    bot = Math.abs( bot );

    var factorX = 1;

    //Find common factors of Numerator and Denominator
    for ( var x = 2; x <= Math.min( top, bot ); x ++ ) {
    var check1 = top / x;
    if ( check1 == Math.round( check1 ) ) {
    var check2 = bot / x;
    if ( check2 == Math.round( check2 ) ) {
    factorX = x;
    }
    }
    }

    top=top/factorX; //divide by highest common factor to reduce fraction

    bot=bot/factorX; //divide by highest common factor to reduce fraction

    return "<sup>"+top+"</sup>/<sub>"+bot+"</sub>";
    }

    function Calculate(value, acc)
    {
    if (value.match(/^d*.?d*$/)) {
    var integer = parseInt(value.match(/^d*.?/)[0]);
    var decimal = parseFloat("0"+value.match(/.d*$/)[0]);
    var rationalise = Math.round(acc*decimal);

    return integer+reduce(rationalise, acc);
    } else {
    return "Wrong Number Format Entered: Please Try Again";
    }
    }
    function frac()
    {
    var valuex = document.forms[0].outputx.value
    var valuey = document.forms[0].outputy.value
    var valuez = document.forms[0].outputz.value
    var acc = document.forms[0].accuracy.value

    var answerx = document.getElementById("answerx");
    var answery = document.getElementById("answery");
    var answerz = document.getElementById("answerz");
    if (acc == "")
    {
    alert("No Accuracy Entered: Please Try Again")
    }
    else
    {
    answerx.innerHTML = Calculate(valuex,acc)
    answery.innerHTML = Calculate(valuey,acc)
    answerz.innerHTML = Calculate(valuez,acc)
    }

    }
    function compute()
    {
    if (document.forms[0].inunit.value==document.forms[0].outunit.value)

    {
    var partA = eval(document.forms[0].inputx.value)/(document.forms[0].scale.value);
    document.forms[0].outputx.value=partA;

    partA = eval(document.forms[0].inputy.value)/(document.forms[0].scale.value);
    document.forms[0].outputy.value=partA;

    partA = eval(document.forms[0].inputz.value)/(document.forms[0].scale.value);
    document.forms[0].outputz.value=partA;

    }
    else
    {
    if (document.forms[0].inunit.value=="inches")

    {
    var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value)
    document.forms[0].outputx.value=partA*2.54
    partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
    document.forms[0].outputy.value=partA*2.54
    partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
    document.forms[0].outputz.value=partA*2.54
    }

    else
    {
    var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value
    )
    document.forms[0].outputx.value=partA/2.54
    partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
    document.forms[0].outputy.value=partA/2.54
    partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
    document.forms[0].outputz.value=partA/2.54
    }

    }
    frac()
    }

    function unit1()
    {
    document.forms[0].inunit.value="centimeters";
    compute();

    }

    function unit2()
    {
    document.forms[0].inunit.value="inches";
    compute();

    }

    function unit3()
    {
    document.forms[0].outunit.value="centimeters";
    compute();

    }

    function unit4()
    {
    document.forms[0].outunit.value="inches";
    compute();

    }

    // Called by Reset button - sets original values.
    function resetIt()
    {
    document.forms[0].scale.value="6";
    document.forms[0].input.value="10";
    document.forms[0].output.value="";

    document.forms[0].inunit.value="inches";

    document.forms[0].outunit.value="inches";

    }

    -->
    </SCRIPT>
    [/code]



    I've had no time to 'pretty' it up or test it properly, as very busy with work at the moment, but will do at some point as it's nice to have decent code...
    ×

    Success!

    Help @ArchAngle spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...