Currency conversion for multiple fields using an entered value
Hi,
I made a Form for monthly expenses and the user has to fill every row with the currency and the amount for every type of cost:
Basically I created hidden text fields for each row where there's the right change rate according to the Date/Currency entered; the total is calculated in the end using another table with the change rate and related date. I tried to use a Document level Java Script but it doesn't work, following the code:
function ChangeRate(){
// there are 24 rows and the fields I need are named VAL.0 (expense), DATE.0 (date), cVAL (number that needs to be multiplied to the cost to get the value in Euros)
var eVal = "VAL";
var eDate = "DATE";
var cVAL = "cVAL";
var N = 24;
// in the form is possible to enter 4 currency change values and I created a variable for each needed field.
// I didn't use the util.scand("dd/mm/yyyy", ___) function because I thought it could work without it but maybe that's the issue idk
var curDate0 = this.getField("cambioData0").value;
var curDate1 = this.getField("cambioData1").value;
var curDate2 = this.getField("cambioData2").value;
var curDate3 = this.getField("cambioData3").value;
var curVal0 = this.getField("cambioV0").valueAsString;
var curVal1 = this.getField("cambioV1").valueAsString;
var curVal2 = this.getField("cambioV2").valueAsString;
var curVal3 = this.getField("cambioV3").valueAsString;
for (var i = 0; i<N; i++){
// tk# are set with the combination of each row name field, t# for the actual values
var tk1 = eVal + "." + i;
var tk2 = eDate + "." + i;
var tk3 = cVAL + "." + i;
var t1 = this.getField(tk1).valueAsString;
var t2 = this.getField(tk2).value;
var t3 = this.getField(tk3);
// first it checks if the currency in the row is EUR so that the field used to calulcate is gonna be 1
if (tok1 == "EUR")
t3.value = 1;
// then it checks if the date and the chosen currency are the same. If so it does 1/changeRate (the value entered is 1€=___ ndr)
else if ((t2 == curDate0) && (t1 == curVal0))
t3.value = 1/this.getField("cRate0").value;
else if ((t2 == curDate1) && (t1 == curVal1))
t3.value = 1/this.getField("cRate1").value;
else if ((t2 == curDate2) && (t1 == curVal2))
t3.value = 1/this.getField("cRate2").value;
else if ((t2 == curDate3) && (t1 == curVal3))
t3.value = 1/this.getField("cRate3").value;
else if ((t2 == curDate4) && (t1 == curVal4))
t3.value = 1/this.getField("cRate4").value;
else t3.value = 1;
}
}
I probably did a mess but anyway.. thank you,
Silvia.
