Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trying to get my script to recognize field in PDF as integer, not text

    I'm at my wits end trying to get what I know is probably something very simple to someone with even a little experience. I've got to add some javascript code to a PDF that will basically take the numbers from a number of other fields, add them up and put them into a field that I designate. Below is the code that I'm using, but all it does is put all the numbers into the field like they were text.

    For example, if the numbers in the fields that I wanted to add together were 1, 5, 10, 20, and 45.5, the result would be 15102045.5

    How do I get the script to recognize that these are integers and not string values? I've renamed the variables and field names for simplicity - they're not really the same values. PLease and thank you for anyone who can provide me with a solution!!!

    Code:
    function CalcAmtFin()
    {
        var A = (this.getField("A").value);
        var B = (this.getField("B").value);
        var C = (this.getField("C").value);
        var D = (this.getField("D").value);
        var E = (this.getField("E").value);
        var F = (this.getField("F").value);
        this.getField("RESULT").value = (A + B + C + D + E + F);
    }
    Last edited by dpgator33; 11-21-2012 at 01:41 PM. Reason: tried to edit thread title

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Input data is a string value until/unless it is changed into a number. The plus symbol + concatenates strings, but adds numbers.

    so ..

    var A = Number(this.getField("A").value);

    and so on.

    But 45.5 is not an integer. I assume you mean a "number".

    You have realised that it is not a good idea to use the same name for an HTML element and a Javascript variable.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 11-21-2012 at 03:22 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    dpgator33 (11-21-2012)

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That helped a lot. After your suggestion, I then got a NaN result in my result field, which led me to change the properties for all the fields from "numeric" to "text" and then it worked. Getting the NaN at least let me know that the correct data was being passed. Again, thanks for the assistance, saved me another headache for sure!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •