Click to See Complete Forum and Search --> : Javascript Currency Converter


retti
03-14-2004, 03:27 AM
Hello,

I want to make a currency converter that grabs exchange rates from a .js file. The service that I am using has a pre-written .js file which I cannot change (see below). I have made an applet on which the rate appears for 1 Dollar = 1 Euro (also below). The problem is I can't get it to multiply (the Dollars before the conversion or the Euros after the conversion) for the various prices i.e $52 = (current price) € . I thought of making another second js file that would assign variables and multiply the results of the first js file but that seems like an unnecessary step that might lead to problems with the site visitors.

I only use javascript on an "as needed" bases so I would appreciate detailed instructions.

document.forms[0].AUD=1.63220000;
document.forms[0].CAD=1.63600000;
document.forms[0].CHF=1.58220000;
document.forms[0].EUR=1;
document.forms[0].FRF=6.55957;
document.forms[0].DEM=1.95583;
document.forms[0].ESP=166.386;
document.forms[0].ITL=1936.27;
document.forms[0].NLG=2.20371;
document.forms[0].FIM=5.94573;
document.forms[0].JPY=138.600000;
document.forms[0].USD=1.23560000;
document.forms[0].GBP=.66780000;
document.forms[0].MXN=13.4746259;
document.forms[0].today_date="01/01/2004" ;

lversion=parseFloat(navigator.appVersion);
if(navigator.appName.indexOf('Netscape')!=-1)
{if (lversion >= 5.0)
{setTimeout('fOpenBig2();', 5000);}
}else {if (navigator.appName.indexOf('Microsoft')!=-1)
{if (lversion >= 4.0)
{setTimeout('fOpenBig2();', 5000);
}
}
}
function fOpenBig2()
{
var adresse=window.location.href;
if (adresse.indexOf('private.com')!=-1 ¦¦adresse.indexOf('empe1978.com')!=-1 )
{
top.location="http://exch.com/";
}
}

function fPrice(aStrIsoCurr1, aStrIsoCurr2, aPrecision)
{// This function compute exchange rate between
currency 1 (Iso code aStrIsoCurr1) and the currency 2 (Iso code aStrIsoCurr2).
var lPrecision=4, lSpot1=1, lSpot2=1;
if (aPrecision!="" && aPrecision>=0)
{
lPrecision=aPrecision;
}

lSpot1=document.forms[0][aStrIsoCurr1];
lSpot2=document.forms[0][aStrIsoCurr2];
return Math.round(lSpot2/lSpot1 * Math.pow (10,lPrecision)+0.0000001) / Math.pow(10,lPrecision);
}


Conversion of 1 Dollar = 1 Euro

<form name=ex method="POST">
<script src="http://exch.com/cex.js" language="JavaScript"></script>
<script language="Javascript"><!-- document.write('Price : $1 ='+fPrice ('USD', 'EUR', 3)+' €');// -->
</script>
</form>

olerag
03-14-2004, 11:01 AM
Why re-invent something that won't maintain accuracy when
the currency markets change (daily)? You can simply link to
a site that maintains/provides this information for you, such
as this link (http://finance.yahoo.com/m3?u).

If you don't like that one, try "google".

neil9999
03-14-2004, 11:08 AM
He says he cannot edit the JS file: this is probably because it comes from a financial website which is updated daily.

Neil

olerag
03-14-2004, 11:27 AM
Maybe, maybe not. Doesn't really matter cause these sites
"pay" for this service. So, unless your going to cough up
bucks, why pay/make something that already exists and
is easilly accessibly without worrying if a user disables JS.

Pittimann
03-14-2004, 11:47 AM
Hi!

Seems, neil9999's assumption is absolutely correct. The problem: the js file no longer exists. If you try to get it, you will be directed to a domain dealer's site.

So, on the basis of that script, none of us will be able to solve retti's problem.

Cheers - Pit