calculations based on drop down and predefined values

Community Beginner ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

Hello,

 

 

Below is my query.

I have one drop-down to select the market

one more drop-down to select the item.

A text field displays the value based on these two selections.

 

also a text field to enter Qty.

Another text field for discount.

 

One more read-only text field displays the final price based on the first text field considering the Qty and the discount.

 

I need to show the profit as well.

Considering all the above, How do I do that.

 

Sharad24656036o6yk_0-1654839025819.png

 

 

Example of the query. (I am no JS expert, Apologies in advance)

If Market is UAE - ECPProfit = Offered Price - (Predefined Value * Qty)

 

I was thinking of something like below.

 

Sharad24656036o6yk_2-1654839025937.png

 

 

 

var mkt = this.getField("DP2").value;

var sell= this.getField(("Text44").value;

var p1= Text32*1000

if (mkt=="UAE - ECP") event.value = sell-p1

 

 

 

Please help me out. I am clueless.

TOPICS
JavaScript , PDF forms

Views

18

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jun 14, 2022 Jun 14, 2022

Copy link to clipboard

Copied

LATEST

The first thing you should do is to use meaningful names for form fields and variables. You may know what Text44 is, but nobody else who might have to work on this form would know that, and there is a pretty good chance that when you put this form aside for a couple of weeks, by the time you come back, you will no longer remberer that bit of information. 

 

You are on the right track (that is as long as your variables are set correctly).  This is what you have today:

var mkt = this.getField("DP2").value;
var sell= this.getField(("Text44").value;
var p1= Text32*1000
if (mkt=="UAE - ECP") event.value = sell-p1

This assumes that it's the calculation script for the result field (otherwise "event.value" will not work for that field). There are a few problems with your code. There is a pretty good chance that the JavaScript editor tried to alert you about some of them, and the JavaScript debugger about the remaining ones. 

 

Your first line is correct, the second line has an extras "(", once you remove that, it will also work. The third line is trying to access something called "Text32", based on the other field with a similar name ("Text44"), I assume it's a form field as well. You need to again use the this.getField("someFieldName").value syntact to get it's value. Once you do that, the script should work:

var mkt = this.getField("DP2").value;
var sell= this.getField("Text44").value;
var p1= this.getField("Text32").value*1000;
if (mkt == "UAE - ECP") {
    event.value = sell-p1;
}

I've added some more structure to make the script easier to read. 

Likes

Translate

Translate

Report

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