Javascript getField returns 0 for a dash/minus symbol

397 views Asked by At

I have a PDF file with calculations. The idea is that the user enters information on a simple form and the data gets replicated multiple times on the same form so they can print the same label 4 times on the same page without entering everything all over again. The calculation for each field is therefore:

event.value = this.getField("Field1").value;

This works well unless someone enters a dash/minus symbol. The calculation then returns 0 instead of the dash. This is the only character this happens on. I presume because it is mathematical in nature, but none of the other operation symbols do this though, so I am confused.

I am using FoxIt PhantomPDF to create the PDF with the formulas. The exact same PDF opened in Adobe Reader XI works perfectly. So I am not sure if this is a JavaScript issue or a FoxIt issue. Thanks!

4

There are 4 answers

0
Max Wyss On BEST ANSWER

If the two fields have the same properties, simply duplicate (copy/paste or duplicate-drag) them. Fields with the same name have the same value; no calculation or other scripting needed.

5
vinayakj On

You need to convert the value to number as value you are getting is string.

event.value = parseFloat(this.getField("Field1").value);
1
Max Wyss On

When it comes to push field values from one field to another, I normally use

this.getField("fieldToPushValueTo").value = event.value ; 

in the Validate event. With this, the field into which the value is pushed remains editable.

Using the Calculate event to transfer the field values does that every time the value of any field in the form gets changed, and does not allow to change the field's value, because it will be replaced immediately.

0
Mike Borman On

Maybe you can append an empty string to prevent the minus from being interpreted as a mathematical operation.

event.value = this.getField("Field1").value + "" ;