Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 12, 2022, 05:52:42 PM

Login with username, password and session length
Members
  • Total Members: 3842
  • Latest: Kokoro
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 50
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 1
Guests: 41
Total: 42

Author Topic: Unit Conversion Calculator  (Read 5432 times)

0 Members and 1 Guest are viewing this topic.

akulion

  • Guest
Unit Conversion Calculator
« on: December 13, 2006, 01:53:04 PM »
Hi

This is a free script I found on the web while script hunting and it works pretty well with TP :D

Demo can be found here on my test site (browse down its in the center)

Put all this code in a article or a center block (even though it would be better off in an article) activate and enjoy.

Code: [Select]
<head>
<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>
</head>
<form name="f">
<table border="1" cellpadding="0" border="1"><tr><td>
<table cellspacing="0" cellpadding="10" border="0" bgcolor="ffedcf">
<tr><td colspan="6" align="center"><h2>Unit Conversion tables</h2></td></tr>
<tr><td colspan="6" align="center">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>
</table></td></tr></table></form>

Offline Crip

  • Jesus Inside.
  • Themes
  • *
  • Posts: 4168
  • Theme Support
    • Cripzone
Re: Unit Conversion Calculator
« Reply #1 on: December 13, 2006, 01:56:15 PM »
Do I need a photo?
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes


Offline Crip

  • Jesus Inside.
  • Themes
  • *
  • Posts: 4168
  • Theme Support
    • Cripzone
Re: Unit Conversion Calculator
« Reply #2 on: December 13, 2006, 01:58:13 PM »
Will you share you nice snowy photo?
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes


Offline Crip

  • Jesus Inside.
  • Themes
  • *
  • Posts: 4168
  • Theme Support
    • Cripzone
Re: Unit Conversion Calculator
« Reply #3 on: December 13, 2006, 02:01:26 PM »
System Error huh? ;D :P
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes


akulion

  • Guest
Re: Unit Conversion Calculator
« Reply #4 on: December 13, 2006, 02:10:14 PM »
lol the big photo u mean? just look below the snowy animation...the zip for it is right there :up:  :D

tapirul

  • Guest
Re: Unit Conversion Calculator
« Reply #5 on: December 18, 2006, 12:53:35 PM »
i am script/languages/etc challenged.. so, how can I make the columns to be squeezed, closer to each other?