Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adobe JavaScript or simplified field to add, multiply several fields to retrieve amount

New Here ,
Jan 09, 2023 Jan 09, 2023

I am running Adobe Pro v. 2022.003.20282 and working on a form (Text Boxes) to pull data from a second sheet.  Problem is I cannot find the right formulas to make what I want to do happen.  I am new and don't know anything about this JavaScripting just Googling and I might be asking too much for the system.

 

basically the formula will see that the TRVL has input their name then look at additional text fields for data to add or multiply for a total dollar amount.

 

(Hotel parking rate will be multiplied by Hotel parking days) then add (Other 1 amount) then add (Other 2 amount) then add (Other 3 person multiplied by Other 3 number of days) to give me the total dollar amount needed.

 

Example - one I have tried which is not calculating it correctly 

var Tname = this.getField("TRVL 1 Name").valueAsString;
var T1cost = this.getField("Hotel parking rate").valueAsString;
var T2cost = this.getField("Hotel parking days").valueAsString;
var T3cost = this.getField("Other 1 amount").valueAsString;
var T4cost = this.getField("Other 2 amount").valueAsString;
var T5cost = this.getField("Other 3 per person").valueAsString
var T6cost = this.getField("Other 3 number of days").valueAsString;
if(Tname != "")
event.value = (T1cost*T2cost)+T3cost+T4cost+(T5cost*T6cost);
else

event.value = "";

 

Example 2 - I have tried

event.value = Math.round((this.getField("Hotel total tax").value * this.getField("Hotel parking days"). value)) + this.getField("Other 1 amount"). value + this.getField("Other 1 amount"). value + this.getField("Other 2 amount"). value) + (this.getField("Other 3 per person").value * this.getField("Other 3 number of days"). value));
event.value = "";

 

Seeing what the pro JavaScript members can come up  with to help me out.

Thanks in advance,

Shannon

1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2023 Jan 09, 2023

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 if it helps you get responses.

 

<moved from using the community>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2023 Jan 09, 2023

What happens when you use the scripts?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2023 Jan 09, 2023

I have put number in the form and they are not populating correctly.

 

Hotel parking rate = $10.00

Hotel parking days = 2
Other 1 amount = $10.00
Other 2 amount = $10.00
Other 3 per person = $10.00
Other 3 number of days = 2

 

So ($10x2)+$10+$10+($10x2)  returns $20,101,020.00 rather than $60 which should be the answer.  I must be missing something in the JavaScript to pull the $60.00.

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2023 Jan 09, 2023

Think I may have figured it out, but I am no pro at JavaScript.  THe script below is pulling the correct amount I want the event.value needed tweeking.  If something still looks wrong let me know.

 

var Tname = this.getField("TRVL 1 Name").valueAsString;
var T1cost = this.getField("Hotel parking rate").valueAsString;
var T2cost = this.getField("Hotel parking days").valueAsString;
var T3cost = this.getField("Other 1 amount").valueAsString;
var T4cost = this.getField("Other 2 amount").valueAsString;
var T5cost = this.getField("Other 3 per person").valueAsString
var T6cost = this.getField("Other 3 number of days").valueAsString;
if(Tname != "")
event.value = (T1cost*T2cost)+(T3cost*1)+(T4cost*1)+(T5cost*T6cost);
else

event.value = "";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2023 Jan 09, 2023
LATEST

It looks fine, but if you want to convert your values to numbers explicitly (so you don't have to multiply them by one), you can use the Number constructor, like this:

 

var T1cost = Number(this.getField("Hotel parking rate").valueAsString);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines