Skip to main content
Participant
August 25, 2024
Question

javascript calcutation help for one with no knowledge of javacript

  • August 25, 2024
  • 2 replies
  • 158 views

HELP!  I want to do 2 simple calculations in text fields in my form.  But I have never done any javascript programming in my life and have no clue how to write the code.  All I know how to do is click on the field, then properties, then the Calculate tab, the custom calculation script button, then edit.  Can someone tell me what to put in the Create and Edit JavaScripts field, please?  Thanks in advance for your help.

 

1. PRICE EA = (PKG PRICE + SH COST)/(QTY/PKG)

2. LINE TOTAL = QTY * (PKG PRICE + SH COST)

    This topic has been closed for replies.

    2 replies

    try67
    Community Expert
    Community Expert
    August 25, 2024

    I recommend reading this tutorial: https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

     

    For "PRICE EA" you can use this code:

     

    var v1 = Number(this.getField("PKG PRICE").valueAsString);
    var v2 = Number(this.getField("SH COST").valueAsString);
    var v3 = Number(this.getField("QTY").valueAsString);
    var v4 = Number(this.getField("PKG").valueAsString);
    
    if (v3==0 || v4==0) event.value = ""; // division by zero is not allowed
    else event.value = (v1+v2)/(v3/v4);
    

     

    For "LINE TOTAL" you can use this code:

     

    var v1 = Number(this.getField("QTY").valueAsString);
    var v2 = Number(this.getField("PKG PRICE").valueAsString);
    var v3 = Number(this.getField("SH COST").valueAsString);
    
    event.value = v1*(v2+v3);

     

    kglad
    Community Expert
    Community Expert
    August 25, 2024

    assuming this is an acrobat question..

     

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

    p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.



    <"moved from using the community">