Forums
This topic is locked
Javascript question, using eval() to return a valu
Posted 16 Oct 2004 18:44:06
1
has voted
16 Oct 2004 18:44:06 Olivier Florence posted:
Hello,i am creating a funtion to calculate the vat and want to get the value ex vat
from a field and return the value including vat to another text field on the
same form.
Because the number of form elements will vary according to user action i need
to pass the form fields name to collect the value and return the result.
This is working fine to collect the value but I am stuck to return the new
value, here is the code i am using:
Tha function is called from the form with:
getVAT('field_name1','filed_name2')
function getVAT(from,to)
{
//collect the value from the form
var price = parseFloat(eval('document.form1.'+from+'.value'));
var incVat = price + (price * 21 / 100);
//return the value
eval('document.form1.'+to+'.value') = incVat;
}
Thanking you in advance
Olivier
Replies
Replied 02 Nov 2004 02:00:12
02 Nov 2004 02:00:12 Seb Adlington replied:
Hi Olivier,
try referencing the form by elements
your code: eval('document.form1.'+to+'.value') = incVat;
change to: document.form1.elements[to].value = incVat;
hope this helps
try referencing the form by elements
your code: eval('document.form1.'+to+'.value') = incVat;
change to: document.form1.elements[to].value = incVat;
hope this helps