free hosting   image hosting   hosting reseller   online album   e-shop   famous people 
Free Website Templates
Free Installer

Area Convertor


This script converts between various units of area, including:
  • Imperial - square inches, feet, miles, acres
  • Metric - square centimetres, metres, kilometres, hectares

  • Paste the code below into the head section of your page:
    And this goes into the body section:

    How It Works


    Form1 holds all the input boxes and dropdown menus:
  • areainput - where you place your conversion number
  • from - the first dropdown menu
  • to - the second dropdown menu
  • calculate - the Calculate button
  • result - the Result box
  • Clicking the Calculate button passes the user's input value to the function convert():
    onClick="convert(Form1.areainput.value)"
    First, all dropdown options are scanned to see which option is selected, and:
  • the from option value is assigned to the variable unita
  • the to option value is assigned to variable unitb
  • When you input a number, its value is assigned to variable ainput.

    This is then processed by parseFloat and assigned to variable invalue.

    The rest of the script simply does the appropriate unit conversions, depending on the parameters selected.


    For example, if you wish to convert square inches to square feet, this section is is called:
    if (unita=="square inches")
    {
        if (unitb=="square feet")
        {
            result = invalue/Math.pow(12,2)
        }
    }
    where:
  • invalue is the user input value
  • Math.pow(12,2) is 12 raised to the power of 2 - ie: 12 x 12 =144
  • result is the value passed to the Result box
  • So if you enter 288 square inches, that value is divided by 144 to give you 2 square feet.


    Try It Out


    Enter an amount, select the appropriate
    units, and click Calculate
    Convert to
    Result :


    © 2001 CyberSchool