FOA I want to apologize because the page below is in Hebrew and you'll see
giberish. But for the brave here is the link. www.carmenchange.com Either
the left or right select box must be set to default (local currency)
otherwise it evaluates the sale with the foreign currencies. Enter the
amount under the foreign currency. Every once in a while if fudges. 2.50 X
10 =24.9........06
for those who can deal with the code
these functions read a file (jk.js) whose format is
var curr1=new Array();
curr1.name="nam e";
curr1.buy='4.46 00';
curr1.sell='4.3 900';
curr1.rep='4.14 80';
.....
currn = etc;
the html contains two select boxes named "inCurrency " and "outCurrenc y" and
two text inputs for them and the functions below process the input from the
text inputs. I've only tested with numbers so feed it at your own risk!!
There are slight differences in the two functions below but both 'seem' to
behave the same. I could really use some help here. I just want to multiply
two values and reformat them. Maybe regexes would be better but I'm weak.
BTW I'm testing with IE5.0 on (phtu) Windows 98
function setOutPrice(amo unt) {
// typeof amount // returns number
if(isNaN(parseI nt(amount))) return false; // extra check for good integer
if(!document.fo rms[0].outCurrency.se lectedIndex) return;
var a,b,obj=documen t.forms[0];
if(obj.inCurren cy.selectedInde x) return;
// I have tried replacing the eval with
// b=window["curr"+obj.outC urrency.selecte dIndex]; b=b.buy;
// and the results are slightly different but just as bad
b=eval("curr"+o bj.outCurrency. selectedIndex+" .buy");
a=parseInt(amou nt)*parseFloat( b);
obj.inPutPrice. value=fixString (a);
}
function setInPrice(amou nt) {
oObj=document.f orms[0].outCurrency;
iObj=document.f orms[0].inCurrency;
if(isNaN(parseI nt(amount))||!i Obj.selectedInd ex) return;
var a,b;
if(oObj.selecte dIndex&&iObj.se lectedIndex) {
forCurrTrans(oO bj,iObj);
return;
}
b=eval('curr'+i Obj.selectedInd ex+'.sell');
a=amount*b;
document.forms[0].outPutPrice.va lue=fixString(a );
}
function fixString(amt) { // trying to fix the results and format
var a = parseInt(amt*10 0)/100+'';
var b=a.indexOf('.' );
if(b==-1) a+='.00';
if(a.length-b==2) a+='0';
return a;
}