• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

Need help seting up money conversion rate on the fly

I am trying to get this example to work http://plugins.jquery.com/project/currency, I am tweaking it
to convert USD to BRL , ( USA to Brazilian Real), but no luck yet..

Any help would be appreciated, or a simple alternative
0
gvilla23
Asked:
gvilla23
  • 4
  • 3
1 Solution
 
leakim971PluritechnicianCommented:
0
 
gvilla23Author Commented:
Let me give it a try, thanks
0
 
Ray PaseurCommented:
What is the important part here?  Currency conversion or jQuery?  If it is the former, maybe this will provide an example and guide.  Please don't copy it and use it without coming up with your own data source!  In other words, don't use 99currencies.com as shown on line 15, thanks.


Best regards, ~Ray
<?php // RAY_currency_converter.php
error_reporting(E_ALL);

// PHP 5.1+  SEE http://us3.php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

class CurrencyConverter
{
    protected $error, $norml, $terse, $verbose, $array, $rates;
    protected static $currs;

    public function __construct()
    {
        // READ THE EXCHANGE RATES
        $url = 'http://www.99currencies.com/currency/curr.php';
        $str = file_get_contents($url);
        $str = str_replace(':CUR', '', $str);
        $this->rates = json_decode($str, TRUE);

        // DATA ADAPTED FROM XE.COM - SEE ALSO: http://en.wikipedia.org/wiki/ISO_4217
        $this->currs["AED"] = array("N" => "United Arab Emirates",                                 "C" => "Dirhams");
        $this->currs["AFN"] = array("N" => "Afghanistan",                                          "C" => "Afghanis");
        $this->currs["ALL"] = array("N" => "Albania",                                              "C" => "Leke");
        $this->currs["AMD"] = array("N" => "Armenia",                                              "C" => "Drams");
        $this->currs["ANG"] = array("N" => "Netherlands Antilles",                                 "C" => "Guilders (also called Florins)");
        $this->currs["AOA"] = array("N" => "Angola",                                               "C" => "Kwanza");
        $this->currs["ARS"] = array("N" => "Argentina",                                            "C" => "Pesos");
        $this->currs["AUD"] = array("N" => "Australia",                                            "C" => "Dollars");
        $this->currs["AWG"] = array("N" => "Aruba",                                                "C" => "Guilders (also called Florins)");
        $this->currs["AZN"] = array("N" => "Azerbaijan",                                           "C" => "New Manats");
        $this->currs["BAM"] = array("N" => "Bosnia and Herzegovina",                               "C" => "Convertible Marka");
        $this->currs["BBD"] = array("N" => "Barbados",                                             "C" => "Dollars");
        $this->currs["BDT"] = array("N" => "Bangladesh",                                           "C" => "Taka");
        $this->currs["BGN"] = array("N" => "Bulgaria",                                             "C" => "Leva");
        $this->currs["BHD"] = array("N" => "Bahrain",                                              "C" => "Dinars");
        $this->currs["BIF"] = array("N" => "Burundi",                                              "C" => "Francs");
        $this->currs["BMD"] = array("N" => "Bermuda",                                              "C" => "Dollars");
        $this->currs["BND"] = array("N" => "Brunei Darussalam",                                    "C" => "Dollars");
        $this->currs["BOB"] = array("N" => "Bolivia",                                              "C" => "Bolivianos");
        $this->currs["BRL"] = array("N" => "Brazil",                                               "C" => "Brazil Real");
        $this->currs["BSD"] = array("N" => "Bahamas",                                              "C" => "Dollars");
        $this->currs["BTN"] = array("N" => "Bhutan",                                               "C" => "Ngultrum");
        $this->currs["BWP"] = array("N" => "Botswana",                                             "C" => "Pulas");
        $this->currs["BYR"] = array("N" => "Belarus",                                              "C" => "Rubles");
        $this->currs["BZD"] = array("N" => "Belize",                                               "C" => "Dollars");
        $this->currs["CAD"] = array("N" => "Canada",                                               "C" => "Dollars");
        $this->currs["CDF"] = array("N" => "Congo/Kinshasa",                                       "C" => "Congolese Francs");
        $this->currs["CHF"] = array("N" => "Switzerland",                                          "C" => "Francs");
        $this->currs["CLP"] = array("N" => "Chile",                                                "C" => "Pesos");
        $this->currs["CNY"] = array("N" => "China",                                                "C" => "Yuan Renminbi");
        $this->currs["COP"] = array("N" => "Colombia",                                             "C" => "Pesos");
        $this->currs["CRC"] = array("N" => "Costa Rica",                                           "C" => "Colones");
        $this->currs["CUP"] = array("N" => "Cuba",                                                 "C" => "Pesos");
        $this->currs["CVE"] = array("N" => "Cape Verde",                                           "C" => "Escudos");
        $this->currs["CYP"] = array("N" => "Cyprus",                                               "C" => "Pounds (expires 2008-Jan-31)");
        $this->currs["CZK"] = array("N" => "Czech Republic",                                       "C" => "Koruny");
        $this->currs["DJF"] = array("N" => "Djibouti",                                             "C" => "Francs");
        $this->currs["DKK"] = array("N" => "Denmark",                                              "C" => "Kroner");
        $this->currs["DOP"] = array("N" => "Dominican Republic",                                   "C" => "Pesos");
        $this->currs["DZD"] = array("N" => "Algeria",                                              "C" => "Algeria Dinars");
        $this->currs["EEK"] = array("N" => "Estonia",                                              "C" => "Krooni");
        $this->currs["EGP"] = array("N" => "Egypt",                                                "C" => "Pounds");
        $this->currs["ERN"] = array("N" => "Eritrea",                                              "C" => "Nakfa");
        $this->currs["ETB"] = array("N" => "Ethiopia",                                             "C" => "Birr");
        $this->currs["EUR"] = array("N" => "Euro Member Countries",                                "C" => "Euro");
        $this->currs["FJD"] = array("N" => "Fiji",                                                 "C" => "Dollars");
        $this->currs["FKP"] = array("N" => "Falkland Islands (Malvinas)",                          "C" => "Pounds");
        $this->currs["GBP"] = array("N" => "United Kingdom",                                       "C" => "Pounds");
        $this->currs["GEL"] = array("N" => "Georgia",                                              "C" => "Lari");
        $this->currs["GGP"] = array("N" => "Guernsey",                                             "C" => "Pounds");
        $this->currs["GHS"] = array("N" => "Ghana",                                                "C" => "Cedis");
        $this->currs["GIP"] = array("N" => "Gibraltar",                                            "C" => "Pounds");
        $this->currs["GMD"] = array("N" => "Gambia",                                               "C" => "Dalasi");
        $this->currs["GNF"] = array("N" => "Guinea",                                               "C" => "Francs");
        $this->currs["GTQ"] = array("N" => "Guatemala",                                            "C" => "Quetzales");
        $this->currs["GYD"] = array("N" => "Guyana",                                               "C" => "Dollars");
        $this->currs["HKD"] = array("N" => "Hong Kong",                                            "C" => "Dollars");
        $this->currs["HNL"] = array("N" => "Honduras",                                             "C" => "Lempiras");
        $this->currs["HRK"] = array("N" => "Croatia",                                              "C" => "Kuna");
        $this->currs["HTG"] = array("N" => "Haiti",                                                "C" => "Gourdes");
        $this->currs["HUF"] = array("N" => "Hungary",                                              "C" => "Forint");
        $this->currs["IDR"] = array("N" => "Indonesia",                                            "C" => "Rupiahs");
        $this->currs["ILS"] = array("N" => "Israel",                                               "C" => "New Shekels");
        $this->currs["IMP"] = array("N" => "Isle of Man",                                          "C" => "Pounds");
        $this->currs["INR"] = array("N" => "India",                                                "C" => "Rupees");
        $this->currs["IQD"] = array("N" => "Iraq",                                                 "C" => "Dinars");
        $this->currs["IRR"] = array("N" => "Iran",                                                 "C" => "Rials");
        $this->currs["ISK"] = array("N" => "Iceland",                                              "C" => "Kronur");
        $this->currs["JEP"] = array("N" => "Jersey",                                               "C" => "Pounds");
        $this->currs["JMD"] = array("N" => "Jamaica",                                              "C" => "Dollars");
        $this->currs["JOD"] = array("N" => "Jordan",                                               "C" => "Dinars");
        $this->currs["JPY"] = array("N" => "Japan",                                                "C" => "Yen");
        $this->currs["KES"] = array("N" => "Kenya",                                                "C" => "Shillings");
        $this->currs["KGS"] = array("N" => "Kyrgyzstan",                                           "C" => "Soms");
        $this->currs["KHR"] = array("N" => "Cambodia",                                             "C" => "Riels");
        $this->currs["KMF"] = array("N" => "Comoros",                                              "C" => "Francs");
        $this->currs["KPW"] = array("N" => "Korea (North)",                                        "C" => "Won");
        $this->currs["KRW"] = array("N" => "Korea (South)",                                        "C" => "Won");
        $this->currs["KWD"] = array("N" => "Kuwait",                                               "C" => "Dinars");
        $this->currs["KYD"] = array("N" => "Cayman Islands",                                       "C" => "Dollars");
        $this->currs["KZT"] = array("N" => "Kazakhstan",                                           "C" => "Tenge");
        $this->currs["LAK"] = array("N" => "Laos",                                                 "C" => "Kips");
        $this->currs["LBP"] = array("N" => "Lebanon",                                              "C" => "Pounds");
        $this->currs["LKR"] = array("N" => "Sri Lanka",                                            "C" => "Rupees");
        $this->currs["LRD"] = array("N" => "Liberia",                                              "C" => "Dollars");
        $this->currs["LSL"] = array("N" => "Lesotho",                                              "C" => "Maloti");
        $this->currs["LTL"] = array("N" => "Lithuania",                                            "C" => "Litai");
        $this->currs["LVL"] = array("N" => "Latvia",                                               "C" => "Lati");
        $this->currs["LYD"] = array("N" => "Libya",                                                "C" => "Dinars");
        $this->currs["MAD"] = array("N" => "Morocco",                                              "C" => "Dirhams");
        $this->currs["MDL"] = array("N" => "Moldova",                                              "C" => "Lei");
        $this->currs["MGA"] = array("N" => "Madagascar",                                           "C" => "Ariary");
        $this->currs["MKD"] = array("N" => "Macedonia",                                            "C" => "Denars");
        $this->currs["MMK"] = array("N" => "Myanmar (Burma)",                                      "C" => "Kyats");
        $this->currs["MNT"] = array("N" => "Mongolia",                                             "C" => "Tugriks");
        $this->currs["MOP"] = array("N" => "Macau",                                                "C" => "Patacas");
        $this->currs["MRO"] = array("N" => "Mauritania",                                           "C" => "Ouguiyas");
        $this->currs["MTL"] = array("N" => "Malta",                                                "C" => "Liri (expires 2008-Jan-31)");
        $this->currs["MUR"] = array("N" => "Mauritius",                                            "C" => "Rupees");
        $this->currs["MVR"] = array("N" => "Maldives (Maldive Islands)",                           "C" => "Rufiyaa");
        $this->currs["MWK"] = array("N" => "Malawi",                                               "C" => "Kwachas");
        $this->currs["MXN"] = array("N" => "Mexico",                                               "C" => "Pesos");
        $this->currs["MYR"] = array("N" => "Malaysia",                                             "C" => "Ringgits");
        $this->currs["MZN"] = array("N" => "Mozambique",                                           "C" => "Meticais");
        $this->currs["NAD"] = array("N" => "Namibia",                                              "C" => "Dollars");
        $this->currs["NGN"] = array("N" => "Nigeria",                                              "C" => "Nairas");
        $this->currs["NIO"] = array("N" => "Nicaragua",                                            "C" => "Cordobas");
        $this->currs["NOK"] = array("N" => "Norway",                                               "C" => "Krone");
        $this->currs["NPR"] = array("N" => "Nepal",                                                "C" => "Nepal Rupees");
        $this->currs["NZD"] = array("N" => "New Zealand",                                          "C" => "Dollars");
        $this->currs["OMR"] = array("N" => "Oman",                                                 "C" => "Rials");
        $this->currs["PAB"] = array("N" => "Panama",                                               "C" => "Balboa");
        $this->currs["PEN"] = array("N" => "Peru",                                                 "C" => "Nuevos Soles");
        $this->currs["PGK"] = array("N" => "Papua New Guinea",                                     "C" => "Kina");
        $this->currs["PHP"] = array("N" => "Philippines",                                          "C" => "Pesos");
        $this->currs["PKR"] = array("N" => "Pakistan",                                             "C" => "Rupees");
        $this->currs["PLN"] = array("N" => "Poland",                                               "C" => "Zlotych");
        $this->currs["PYG"] = array("N" => "Paraguay",                                             "C" => "Guarani");
        $this->currs["QAR"] = array("N" => "Qatar",                                                "C" => "Rials");
        $this->currs["RON"] = array("N" => "Romania",                                              "C" => "New Lei");
        $this->currs["RSD"] = array("N" => "Serbia",                                               "C" => "Dinars");
        $this->currs["RUB"] = array("N" => "Russia",                                               "C" => "Rubles");
        $this->currs["RWF"] = array("N" => "Rwanda",                                               "C" => "Rwanda Francs");
        $this->currs["SAR"] = array("N" => "Saudi Arabia",                                         "C" => "Riyals");
        $this->currs["SBD"] = array("N" => "Solomon Islands",                                      "C" => "Dollars");
        $this->currs["SCR"] = array("N" => "Seychelles",                                           "C" => "Rupees");
        $this->currs["SDG"] = array("N" => "Sudan",                                                "C" => "Pounds");
        $this->currs["SEK"] = array("N" => "Sweden",                                               "C" => "Kronor");
        $this->currs["SGD"] = array("N" => "Singapore",                                            "C" => "Dollars");
        $this->currs["SHP"] = array("N" => "Saint Helena",                                         "C" => "Pounds");
        $this->currs["SLL"] = array("N" => "Sierra Leone",                                         "C" => "Leones");
        $this->currs["SOS"] = array("N" => "Somalia",                                              "C" => "Shillings");
        $this->currs["SPL"] = array("N" => "Seborga",                                              "C" => "Luigini");
        $this->currs["SRD"] = array("N" => "Suriname",                                             "C" => "Dollars");
        $this->currs["STD"] = array("N" => "S&atilde;o Tome and Principe",                         "C" => "Dobras");
        $this->currs["SVC"] = array("N" => "El Salvador",                                          "C" => "Colones");
        $this->currs["SYP"] = array("N" => "Syria",                                                "C" => "Pounds");
        $this->currs["SZL"] = array("N" => "Swaziland",                                            "C" => "Emalangeni");
        $this->currs["THB"] = array("N" => "Thailand",                                             "C" => "Baht");
        $this->currs["TJS"] = array("N" => "Tajikistan",                                           "C" => "Somoni");
        $this->currs["TMM"] = array("N" => "Turkmenistan",                                         "C" => "Manats");
        $this->currs["TND"] = array("N" => "Tunisia",                                              "C" => "Dinars");
        $this->currs["TOP"] = array("N" => "Tonga",                                                "C" => "Pa&apos;anga");
        $this->currs["TRY"] = array("N" => "Turkey",                                               "C" => "New Lira");
        $this->currs["TTD"] = array("N" => "Trinidad and Tobago",                                  "C" => "Dollars");
        $this->currs["TVD"] = array("N" => "Tuvalu",                                               "C" => "Tuvalu Dollars");
        $this->currs["TWD"] = array("N" => "Taiwan",                                               "C" => "New Dollars");
        $this->currs["TZS"] = array("N" => "Tanzania",                                             "C" => "Shillings");
        $this->currs["UAH"] = array("N" => "Ukraine",                                              "C" => "Hryvnia");
        $this->currs["UGX"] = array("N" => "Uganda",                                               "C" => "Shillings");
        $this->currs["USD"] = array("N" => "United States of America",                             "C" => "Dollars");
        $this->currs["UYU"] = array("N" => "Uruguay",                                              "C" => "Pesos");
        $this->currs["UZS"] = array("N" => "Uzbekistan",                                           "C" => "Sums");
        $this->currs["VEB"] = array("N" => "Venezuela",                                            "C" => "Bolivares (expires 2008-Jun-30)");
        $this->currs["VEF"] = array("N" => "Venezuela",                                            "C" => "Bolivares Fuertes");
        $this->currs["VND"] = array("N" => "Viet Nam",                                             "C" => "Dong");
        $this->currs["VUV"] = array("N" => "Vanuatu",                                              "C" => "Vatu");
        $this->currs["WST"] = array("N" => "Samoa",                                                "C" => "Tala");
        $this->currs["XAF"] = array("N" => "Communaut&eacute; Financi&egrave;re Africaine BEAC",   "C" => "Francs");
        $this->currs["XAG"] = array("N" => "Silver",                                               "C" => "Ounces");
        $this->currs["XAU"] = array("N" => "Gold",                                                 "C" => "Ounces");
        $this->currs["XCD"] = array("N" => "East Caribbean",                                       "C" => "Dollars");
        $this->currs["XDR"] = array("N" => "IMF Special Drawing Rights",                           "C" => "XDR");
        $this->currs["XOF"] = array("N" => "Communaut&eacute; Financi&egrave;re Africaine BCEAO",  "C" => "Francs");
        $this->currs["XPD"] = array("N" => "Palladium",                                            "C" => "Ounces");
        $this->currs["XPF"] = array("N" => "Comptoirs Fran&ccedil;ais du Pacifique Francs",        "C" => "CFP Francs");
        $this->currs["XPT"] = array("N" => "Platinum",                                             "C" => "Ounces");
        $this->currs["YER"] = array("N" => "Yemen",                                                "C" => "Rials");
        $this->currs["ZAR"] = array("N" => "South Africa",                                         "C" => "Rand");
        $this->currs["ZMK"] = array("N" => "Zambia",                                               "C" => "Kwacha");
        $this->currs["ZWD"] = array("N" => "Zimbabwe",                                             "C" => "Zimbabwe Dollars");

        // ELIMINATE THE MISMATCHED ITEMS
        $this->norml = $this->normalArrays();
    }

    public function getRates()
    {
        return $this->rates;
    }

    public function getCurrs()
    {
        return $this->currs;
    }

    public function getNormalization()
    {
        return $this->norml;
    }

    public function getError()
    {
        return $this->error;
    }

    public function asTerse()
    {
        return $this->terse;
    }

    public function asVerbose()
    {
        return $this->verbose;
    }

    public function asArray()
    {
        return $this->array;
    }

    public function normalArrays()
    {
        $response = NULL;
        foreach ($this->currs as $code => $x)
        {
            if (!isset($this->rates[$code]))
            {
                $response .= PHP_EOL . "$code IS IN CURRENCIES BUT NOT IN RATES";
                unset($this->currs[$code]);
            }
        }
        if ($response) $response .= PHP_EOL;
        foreach ($this->rates as $code => $x)
        {
            if (!isset($this->currs[$code]))
            {
                $response .= PHP_EOL . "$code IS IN RATES BUT NOT IN CURRENCIES";
                unset($this->rates[$code]);
            }
        }
        return $response;
    }

    public function isCurrency($code)
    {
        if (isset($this->rates[$code]))
        {
            return $this->rates[$code];
        }
        return FALSE;
    }

    public function convert($amount, $source_currency, $result_currency, $decimals=6)
    {
        // NORMALIZE DATA
        $this->array   = array();
        $this->error   = NULL;
        $this->terse   = NULL;
        $this->verbose = NULL;

        $source_currency = trim(strtoupper($source_currency));
        if (!isset($this->currs[$source_currency]))
        {
            $this->error .= "Currency $source_currency not found" . PHP_EOL;
        }

        $result_currency = trim(strtoupper($result_currency));
        if (!isset($this->currs[$result_currency]))
        {
            $this->error .= "Currency $result_currency not found" . PHP_EOL;
        }

        if ($this->error) return FALSE;

        // COMPUTE THE CONVERSION
        $rezult = 1.0 / $this->rates[$source_currency] * $this->rates[$result_currency] * $amount;

        //PREPARE THE RESPONSES
        $this->array
        = array
        ( "$source_currency" => number_format($amount, $decimals, '.', '')
        , "$result_currency" => number_format($rezult, $decimals, '.', '')
        )
        ;

        $this->terse
        = $this->array[$source_currency]
        . $source_currency
        . '='
        . $this->array[$result_currency]
        . "$result_currency"
        ;

        $this->verbose
        = $this->array[$source_currency]
        . ' '
        . $source_currency
        . ' ('
        . $this->currs[$source_currency]['N']
        . ' '
        . $this->currs[$source_currency]['C']
        . ')'
        . ' = '
        . $this->array[$result_currency]
        . ' '
        . $result_currency
        .' ('
        . $this->currs[$result_currency]['N']
        . ' '
        . $this->currs[$result_currency]['C']
        . ')'
        ;
        return (string)$rezult;
    }
}

// DEMONSTRATION SCRIPT
echo '<pre>';
$cc = new CurrencyConverter;

// GET THE SPOT PRICE OF AN OUNCE OF GOLD
echo PHP_EOL . 'THE PRICE OF GOLD IS $' . number_format($cc->convert(1.0, 'XAU', 'USD', 2),2);


// CONVERT 3 BRITISH POUNDS TO US DOLLARS
echo PHP_EOL . $cc->convert(3.0, 'gbp', 'usd', 2);

// IF ANY ERROR OCCURRED
if ($cc->getError()) echo PHP_EOL . $cc->getError();

// SHOW THE THREE RETURN METHODS
echo PHP_EOL . $cc->asTerse();
echo PHP_EOL . $cc->asVerbose();
echo PHP_EOL;  var_dump($cc->asArray());


// SHOW ERROR HANDLING - CONVERT 2 FOOS TO BARS
echo PHP_EOL . $cc->convert(2, 'Foo', 'Bar');

// IF ANY ERROR OCCURRED
if ($cc->getError()) echo PHP_EOL . $cc->getError();

// SHOW THE THREE RETURN METHODS
echo PHP_EOL . $cc->asTerse();
echo PHP_EOL . $cc->asVerbose();
echo PHP_EOL;  var_dump($cc->asArray());


// IF A FORM WAS SUBMITTED
if (!empty($_GET))
{
    $getResult = $cc->convert($_GET['a'], $_GET['f'], $_GET['t']);

    // IF ANY ERROR OCCURRED
    if ($cc->getError()) echo PHP_EOL . $cc->getError();

    // SHOW THE THREE RETURN METHODS
    echo PHP_EOL . $cc->asTerse();
    echo PHP_EOL . $cc->asVerbose();
    echo PHP_EOL;  var_dump($cc->asArray());
}


// CREATE A FORM FOR THE CLIENT
echo '<form>';

echo 'AMOUNT TO CONVERT: ';
echo '<input name="a" />';

echo '<br/>CHOOSE "FROM" CURRENCY';
echo '<br/><select name="f">' . PHP_EOL;
echo '<option value="NUL" selected="selected">CHOOSE CURRENCY</option>' . PHP_EOL;
foreach ($cc->getCurrs() as $code => $arr)
{
    echo '<option value="';
    echo $code;
    echo '">';
    echo $arr['N'];
    echo ' ';
    echo $arr['C'];
    echo '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;

echo '<br/>CHOOSE "TO" CURRENCY';
echo '<br/><select name="t">' . PHP_EOL;
echo '<option value="NUL" selected="selected">CHOOSE CURRENCY</option>' . PHP_EOL;
foreach ($cc->getCurrs() as $code => $arr)
{
    echo '<option value="';
    echo $code;
    echo '">';
    echo $arr['N'];
    echo ' ';
    echo $arr['C'];
    echo '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;

echo '<input type="submit" />';
echo '</form>';

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
gvilla23Author Commented:
I need to get the conversion rate to display on the page as text, it popsup and displayst it

<html>

<-- Get exchange rate as JSONP via YQL.

YQL Console: http://developer.yahoo.com/yql/console

Query (USD to SEK): select rate,name from csv where url='http://download.finance.yahoo.com/d/quotes?s=USDSEK%3DX&f=l1n' and columns='rate,name'

Example code:

-->
<script type="text/javascript">

  function getRate(from, to) {
    var script = document.createElement('script');
    script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+from+to+"%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
    document.body.appendChild(script);
  }

  function parseExchangeRate(data) {
    var name = data.query.results.row.name;
    var rate = parseFloat(data.query.results.row.rate, 10);
   

    alert("Exchange rate " + name + " is " + rate);
  }
 
 // getRate("SEK", "USD");
  getRate("USD", "BRL");
 
</script>



<br>
<br>
The price for this is:
<Script Language="JavaScript">
document.write(rate);</Script>


</html>
0
 
gvilla23Author Commented:
Thanks Ray_Paseur, the important thing is the  Currency conversion.
0
 
leakim971PluritechnicianCommented:
Check the following :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">

	function getRate(from, to) {
		var script = document.createElement('script');
		script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+from+to+"%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
		document.body.appendChild(script);
	}
	
	function parseExchangeRate(data) {
		var name = data.query.results.row.name;
		var rate = parseFloat(data.query.results.row.rate, 10);
		document.getElementById("here").innerHTML = "Exchange rate " + name + " is " + rate;
	}
	
	window.onload = function() {
		getRate("USD", "BRL")
	}
  
</script>
</head>
<body>
<br>
<br>
<div id="here"></div>
</body>
</html>

Open in new window

0
 
gvilla23Author Commented:
Thanks again =)
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now