onChange - add up numbers (web)

I have this JavaScript code in the onChange event on a field. The result is that the field ‘sum’ should show the sum of the variables.

  1. This work well but the number is an integer - how can I get it to be decimal numeral?

  2. The ‘sum’-field is of type editable. I actual want the field to be computed so the user can’t write in the field… how can I do this? If I change the field to computet my code doesn’t work…

var f = document.forms[0]

cal1 = f.Ant1.value * 49

cal2 = f.Ant2.value * 2,85

cal3 = f.Ant3.value * 15,50

cal4 = f.Ant4.value * 2,95

f.Sum.value = cal1 + cal2 + cal3 + cal4

Subject: onChange - add up numbers (web)

  1. You’re right, the field does have to be editable in order to modify it with JS without a round trip to the server. To prevent data entry, you can add this.blur() to the field’s onFocus event. You can also try adding readonly or disabled to the field’s HTML “other” properties but make sure it works in all the required browsers.