Java Script unit converter

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
Joined
Jul 8, 2007
Messages
628
Reaction score
14
This is a new little deal I added that may aid in helping converting one unit to the other and is simple.

you will see the link in the menu on the top left but here is the link.

http://www.homemodelenginemachinist.com/index.php?page=10

If you find any bugs please report them and I will beat my brains and try to fix them.

Enjoy.

If any of you program javascript, php or html and wish to subit a tool like this then let me know and we will see what we can do.


I know mklotz does many great tools and maybe if he would like we could try and make some of his applications web based, maybe add to thier funtions.

here is the code for anyone who wants to see it...

Code:
<script language="javascript">
function convert(index){
var tmp=new Object();
var d=document.f;
tmp.name=units[index];
tmp.t1=d[('t1'+tmp.name)].value
if(typeof parseInt(tmp.t1) != "number"){
tmp.t1=1;
d[('t1'+tmp.name)].value=1;
}
tmp.s1=d[('s1'+tmp.name)].selectedIndex;
tmp.s2=d[('s2'+tmp.name)].selectedIndex;
tmp.c1=eval(units[index]+'['+tmp.s1+'][1]');
tmp.c2=eval(units[index]+'['+tmp.s2+'][1]');
tmp.result=''+eval(tmp.t1+'*'+tmp.c1+'/'+tmp.c2);
tmp.test=tmp.result.indexOf("e");
if(tmp.test!=(-1)){
tmp.test=tmp.result.substring(tmp.test,tmp.result.length);
tmp.result=tmp.result.substring(0,10)+tmp.test
}else{
tmp.result=tmp.result.substring(0,13)
}
d[('t2'+tmp.name)].value=tmp.result;
}

var units=[ 'Length' , 'Area' , 'Volume' , 'Time' , 'Speed' , 'Mass' , 'Power' ];

var Length=[
['inch','.0254'],
['foot','.3048'],
['yard','.9144'],
['mile','1609.344'],
['nautical mile','1852'],
['fathom','1.82880365761'], 
['rod','5.02921005842'],
['chain','20.1168402337'],
['millimeter','.001'],
['centimeter','.01'],
['meter','1'],
['kilometer','1000']
]

var Area=[
['square meter','1'],
['square centimeter','.0001'],
['square yard','.83612736'],
['square feet','.09290304'],
['square inch','.00064516'],
['square kilometer','1000000'],
['acre','4046.87260987'],
['square mile','2589988.11034']
]

var Volume=[
['cubic meter','1'],
['cubic centimeter','.000001'],
['milliliter','.000001'],
['liter','.001'],
['cubic yard','.764554857984'],
['cubic feet','.028316846592'],
['cubic inch','.000016387064'],
['gallons','.003785411784'],
['quart','.000946352946'],
['pints','.000473176473'],
['fluid ounce','.0000295735295625'],
['tablespoon','.000014786747813'],
['teaspoon','.00000492892159375']
]

var Time=[
['second','1'],
['minute','60'],
['hour','3600'],
['day','86400'],
['week','604800'],
['year','31556925.9747']
]

var Speed=[
['meters/sec','1'],
['centimeters/sec','.01'],
['feet/sec','.3048'],
['kilometer/hour','.277777777778'],
['miles/hour','.44704'],
['knots','.514444444444'],
['C','299792458']
]

var Mass=[
['gram','1'],
['kilogram','1000'],
['ounce','28.349523125'],
['pound','453.59237'],
['slug','14593.9029372'],
['ton','907184.74']
]

var Power=[
['watts','1'],
['horsePower','745.699871582']
]
</script>
<form name="f">
  <table cellpadding="0" border="1">
    <tbody>
      <tr>
        <td>
        <table cellspacing="0" cellpadding="10" bgcolor="#ffedcf" border="0">
          <tbody>
            <tr>
              <td align="center" colspan="6">
              <h2>Unit Conversion tables</h2>
              </td>
            </tr>
            <tr>
              <td align="center" colspan="6">Simply enter a number in the first text box, select unit, and then select unit to convert to.<br />
              Your Answer will appear in the second text box.</td>
            </tr>
            <script language="javascript">
var t='';
for(i=0;i<units.length;i++){
t+='<tr><td colspan="6"><hr width="100%" color="black"><font size="+2">'+units[i]+'</font></td></tr>';
t+='<tr><td><input type="text" value="1" name="t1'+units[i]+'" size="5" onChange="convert('+i+')"></td><td>';
t+='<select name="s1'+units[i]+'" onChange="convert('+i+')">';
for(j=0;j<eval(units[i]+'.length');j++)t+='<option>'+eval(units[i]+'['+j+'][0]')+'</option>';
t+='</select></td><td align="center">To</td><td>';
t+='<select name="s2'+units[i]+'" onChange="convert('+i+')">';
for(j=0;j<eval(units[i]+'.length');j++)t+='<option>'+eval(units[i]+'['+j+'][0]')+'</option>';
t+='</select></td><td>=</td>';
t+='<td><input type="text" readonly value="1" name="t2'+units[i]+'" size="14">';
t+='</td></tr>';
}
document.write(t);
</script>
          </tbody>
        </table>
        </td>
      </tr>
    </tbody>
  </table>
</form>
 
Mike, the system seems to not let me select the units of conversion in either table. It looks very handy, though!
 
Could come in handy, but reducing it in size would be a big plus. Looks sort of Internet circa 1996 at that size.

Steve
 
wareagle said:
Mike, the system seems to not let me select the units of conversion in either table. It looks very handy, though!

Security, you have to do that yourself in settings and java script. Im 99% sure of that.

I admin 6+ sites and have heard all the errors but I thank you for telling me or else i would not know.

I will look at it more, thank you..
 
Is there any way to script the Google converter? It knows a tremendous amount of units, so you can ask it "73 feet in furlongs" and get a meaningful answer.

What I'd like to see is a 'closest metric / imperial' converter, so when somebody says "3 BA", I can pop it up and get "close to 3/4-16" (or whatever the correct 'closest' is.. I know that's not it)
 
Shred,

I think I put this up once before, but it's probably worth repeating.

British Association Closest American
Threads Threads

BA OD TPI PITCH THREAD OD
Size (in) (mm) (in)

16 0.031 134.0 0.19
15 0.035 121.0 0.21
14 0.039 110.0 0.23
13 0.047 102.0 0.25
12 0.051 90.9 0.28 0-80 0.060
11 0.059 82.0 0.31
10 0.066 72.6 0.35 1-72 0.073
9 0.075 65.1 0.39
8 0.087 59.1 0.43 2-56 0.086
7 0.098 52.9 0.48 3-48 0.099
6 0.110 47.9 0.53 4-48 0.112
5 0.126 43.0 0.59 5-44 0.125
4 0.142 38.5 0.66 6-40 0.138
3 0.161 34.8 0.73 8-32 0.164
2 0.185 31.4 0.81 10-32 0.190
1 0.209 28.2 0.90 12-28 0.216
0 0.236 25.4 1.00 1/4-28 0.250

Notes from ME-05/05/95-529 Post Bag letter by Jim Nicholson
Full series runs from 0 to 22.
Thread angle = 47.5 deg.
Crest and root radii = 0.18p (p=pitch)
Pitches are calculated as p(mm) = 0.9^n (n=number of thread in BA series)
Diameters are calculated as D(mm) = 6p^1.2
Running:

FOR N=22 TO 0 STEP -1 : P=0.9^N : D=6*P^1.2
PRINT USING "## #.### ###.# #.###";N;D/25.4;25.4/P;P
NEXT

produces:

N OD TPI PITCH
(in) (mm)
22 0.015 257.9 0.098
21 0.017 232.1 0.109
20 0.019 208.9 0.122
19 0.021 188.0 0.135
18 0.024 169.2 0.150
17 0.028 152.3 0.167
16 0.031 137.1 0.185
15 0.035 123.4 0.206
14 0.040 111.0 0.229
13 0.046 99.9 0.254
12 0.052 89.9 0.282
11 0.059 80.9 0.314
10 0.067 72.8 0.349
9 0.076 65.6 0.387
8 0.086 59.0 0.430
7 0.097 53.1 0.478
6 0.111 47.8 0.531
5 0.126 43.0 0.590
4 0.142 38.7 0.656
3 0.162 34.8 0.729
2 0.183 31.4 0.810
1 0.208 28.2 0.900
0 0.236 25.4 1.000

British Std Whitworth British Standard Fine
Thread TPI Tap Drill TPI Tap Drill
1/8 40 2.55 mm
3/16 24 3.70 mm 32 5/32
7/32 28 4.65 mm
1/4 20 5.10 mm 26 5.30 mm
9/32 26
5/16 18 6.50 mm 22 6.75 mm
3/8 16 5/16 20 8.25 mm
7/16 14 9.25 mm 18 9.70 mm
1/2 12 10.5 mm 16 7/16
9/16 12 12.10 mm 16 1/2
5/8 11 13.50 mm 14 14.00 mm
11/16 11 14
3/4 10 41/64 12 16.75 mm
7/8 9 19.25 mm 11 25/32
1 8 22.00 mm 10 22.75 mm
1-1/8 7 24.75 mm 9 25.50 mm
1-1/4 7 1-3/32 9 28.75 mm
1-3/8 8 31.50 mm
1-1/2 6 33.50 mm 8 1-23/64
1-3/4 5 39.00 mm
2 4.5 44.50 mm
 
This is a bit off topic but perhaps someone more knowledgeable than I can help.

I have a lot of metalworking data stored on my computer as tab-delimited tables in ordinary text files. Every time I copy such a table into a post, the !@#$%^&ing proportional font crapola messes up the table spacing - see example in my post above.

Is there some html command or similar that can I can use to prevent this?
 
Thanks Marv, that's what I was looking for. Now all we need is to crank it into the calculator..

There are some monospaced fonts you could try, but the big problem is HTML crunches excess white spaces together and doesn't respect tabs. I see a lot of formatting options for text, so maybe one of those will work. You could try 'Code' and see if that helps.

edit: hmm. there's a 'Preformatted text' option on this forum SW (just to the right of the <-Marquee box).. let's see how it does
Code:
   Thing 1   Thing 2
    Cat     Hat
Not too bad.. just a little off. Still doesn't seem to respect tabs properly, but the font is monospaced.
 

Latest posts

Back
Top