Hi
I have a switch statement in a form I have created for a drop down list which has two options. My simple code is as follows:
-------------------------------------------------
var i = parseInt(event.srcElement.returnValue, 10);
var h = parseFloat(crmForm.netamount.value, 10);
switch(i)
{
case 1:
window.alert("Please click 'Calculate VAT' option below");
i=0.00;
break;
case 2:
i=parseFloat((h*1.175)-h, 10);
break;
}
parseFloat(crmForm.tax.value, 10) = i;
----------------------------------------------------------
The purpose of the drop down list is to calculate VAT (tax which is 17.5%) based on what the net amount is. The net amount field is called "netamount" and my VAT/tax field is called "tax".
When option 2 in the drop down list is clicked the VAT is calculated by multiplying netamount(h) by 1.175. The netamount(h) is then subtracted from this result to get the VAT separately.
Initially the tax field was getting populated with a NaN result, which I resolved by using ParseFloat on all the variables. However I have found a problem with my function above - it does not calculate (h) correctly. It thinks the value is 1000 times smaller than it actually is. For example if the netamount(h) in fact equals 6000 my function thinks it is 6. Also, it seems to ignore the last 3 digits to the left of the number... it only sees the first digit on the left for example even if the number is 6750 or 6900 it still sees 6. If the netamount for example equals 21500, my function will only see 21. It seems to be 3 significant places out (if that is the term).
Please can anyone see where I am going wrong. I assume the problem may lie with the fact I am using parseInt for the variable (i) at the top. However I was lead to believe I need to use this as the drop down list ID values are either 1 or 2 for each option, both being integers, therefore I need parseInt (this is in the first line of the code where I declare (i) )
Many thanks for any help resolving this problem.
Les
I have a switch statement in a form I have created for a drop down list which has two options. My simple code is as follows:
-------------------------------------------------
var i = parseInt(event.srcElement.returnValue, 10);
var h = parseFloat(crmForm.netamount.value, 10);
switch(i)
{
case 1:
window.alert("Please click 'Calculate VAT' option below");
i=0.00;
break;
case 2:
i=parseFloat((h*1.175)-h, 10);
break;
}
parseFloat(crmForm.tax.value, 10) = i;
----------------------------------------------------------
The purpose of the drop down list is to calculate VAT (tax which is 17.5%) based on what the net amount is. The net amount field is called "netamount" and my VAT/tax field is called "tax".
When option 2 in the drop down list is clicked the VAT is calculated by multiplying netamount(h) by 1.175. The netamount(h) is then subtracted from this result to get the VAT separately.
Initially the tax field was getting populated with a NaN result, which I resolved by using ParseFloat on all the variables. However I have found a problem with my function above - it does not calculate (h) correctly. It thinks the value is 1000 times smaller than it actually is. For example if the netamount(h) in fact equals 6000 my function thinks it is 6. Also, it seems to ignore the last 3 digits to the left of the number... it only sees the first digit on the left for example even if the number is 6750 or 6900 it still sees 6. If the netamount for example equals 21500, my function will only see 21. It seems to be 3 significant places out (if that is the term).
Please can anyone see where I am going wrong. I assume the problem may lie with the fact I am using parseInt for the variable (i) at the top. However I was lead to believe I need to use this as the drop down list ID values are either 1 or 2 for each option, both being integers, therefore I need parseInt (this is in the first line of the code where I declare (i) )
Many thanks for any help resolving this problem.
Les