Forum Moderators: open
function fix(thenumber,noplaces){ // returns the number to n decimal places
var oldnumber=thenumber;
thenumber=thenumber+"0000";
var decpos=thenumber.indexOf(".");
if (decpos==-1) return oldnumber+".00";
decpos=decpos+noplaces+1;
var endstring=thenumber.substring(0,decpos);
return endstring;
}
function convert_currency(){
//var dollarval=document.converter.original.value/ConversionFactor(document.converter.sourcecurrency.value);
//document.converter.converted.value=fix(dollarval*ConversionFactor(document.converter.targetcurrency.value),2);
var dollarval= document.form.gbp.value;
document.form.usd.value=fix(dollarval*1.85,2);
document.form.eur.value=fix(dollarval*1.46,2);
}
function convert_currency_spec(){
//var dollarval=document.converter.original.value/ConversionFactor(document.converter.sourcecurrency.value);
//document.converter.converted.value=fix(dollarval*ConversionFactor(document.converter.targetcurrency.value),2);
var dollarval= document.form.special_offer_original_gbp.value;
document.form.special_offer_original_usd.value=fix(dollarval*1.85,2);
document.form.special_offer_original_eur.value=fix(dollarval*1.46,2);
}
document.form
to:
document.forms[0]
Other than that it seemed to work OK. This references the first form on the page. If you have more than 1 form, however, this could get problematic. Best to use the form name, as in:
document.forms['myform'] (...)
<form name="myform" (...)
Pretty good rate of exchange!
Added:
Just checking.... you are not rounding your results, you are just 'chopping off' after the 2nd decimal place. Is that ok? ie. 5.099999 becomes 5.09, whereas it should be 5.10 to two decimal places.