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

Please how do i add code to enable addition? *All details below*

Community Beginner ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

i have a drop down with this code: 

} else if (event.value=="") {
this.getField("Text1").value = "1";
this.getField("Text2").value = "";
this.getField("Text3").value = "KG"
} else {
this.getField("Text1").value = "1";
this.getField("Text2").value = "";
this.getField("Text3").value = "KG";
}

I am trying to add code so i can add all of the weights together for the net weight to be populated in another text box. is this possible and can anyone help me do it please? thank you!

TOPICS
JavaScript

Views

2.3K

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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Here is your file with changes made (Step 1), first two fields will work, rest you need to fill on your own:

https://drive.google.com/file/d/1QKDb1RA01bM8x7BGNaz89FBPQVPLNUG1/view?usp=sharing 

View solution in original post

Votes

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
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Code is missing a part, also can you explain exactly what you try to do, include field names and dropdown choices in your description.

Votes

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
Community Beginner ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Charlie303735890y2h_0-1725963620654.png

 

so the way i have done it is very long winded. as you can see i have 3 text boxes that get popoulated with information on each line when a selection is mae from the dropdown with the following code: 

} else if (event.value=="GCR0020") {
this.getField("Text1").value = "1";
this.getField("Text2").value = "";
this.getField("Text3").value = "KG"
} else {
this.getField("Text1").value = "1";
this.getField("Text2").value = "";
this.getField("Text3").value = "KG";
}
 
i added this to every line on the dropdown. then i changed each text box to be different and changed each name of each line. the automated lines of code on the first row is QTY11, DESCRIPTION11 & WEIGHT11. The next line is qty1.1,description1.1,weight1.1 and so on for the rest of the document. each line the only thing that changes is the numbers. 
 
Hopefully that all makes sense and gives you some insight into how it works!

Votes

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
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Still doesn't explain what you try to do, do you have a working script, but you need a shorter script?

 

Votes

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
Community Beginner ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

if i could have one line bit of code instead of 40 lines of seperate code that would be immense. i am not sure if thats possible though...

 

the actual reason for my post however is i am trying to automate weight calculations.

 

context: when a selection is selected from the drop down a weight appears for example 12kg. i would like each line of code that gets added to be shown as a net/overal weight. i would like some code that adds up each line of weight. for example if the qty goes from 1 to 2. i would like the weight to go from 12kg to 24. if there is 4 lines of 12kg i would like the code to populate a net weight and say: 48kg 

 

hopefully this helps and i have explained thoroughly enough. if not i will be happy to give you more information!

Votes

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
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

If I understood you, you don't need scripts for this, in qty fields go to options tab and as default value enter 1, same for weight fields enter default value of KG.

To calculate weight, go to each weight field and under 'calculate' tab select, 'Value is the' and select product(x), now click on 'pick' and select corresponding qty field for that weight field.

To calculate total weight go to total weight properties and under 'calculate' tab select 'Value is the' (leave as sum(+)) and pick all the weight fields.

Votes

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
Community Beginner ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

i did what you said and the gross weight is stuck at 0. i selected everything you said. when i select multiple weights it does not add the weights. it stays at 0. 

Votes

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
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Votes

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
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Can you share your file so I can see what is going on?

Votes

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
Community Beginner ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

Here you go. thank you very much for all the help!

Votes

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
Community Expert ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

I see now what you try to do, I would suggest you a couple of different approaches.

1. Remove ALL scripts you have from dropdown fields and the one from "QTY13" field also.

Place this as document level script:

function cDrop(qtyField, descField, weightField) {
 var items = {
  "XCR0051": {qty: "1", desc: "24\" CRAWLER CHASSIS FOR ICM", weight: "KG"},
  "PCR2400": {qty: "1", desc: "24CR2 CHASSIS", weight: "61.8"}
//fill the rest of the list here
};

 var item = items[event.value] || {qty: "1", desc: "", weight: "KG"};

 this.getField(qtyField).value = item.qty;
 this.getField(descField).value = item.desc;
 this.getField(weightField).value = item.weight;
}

Now go to first row dropdown and as 'Validate' script use this:

cDrop("QTY11", "Description11", "Weight11");

Repeat for other rows just change field names, for example for row 2 it would be:

cDrop("QTY1.1", "Description1.11.1", "Weight1.11.1");...etc for rest of the rows.

Also in each dropdown field under 'Options' tab, check 'Commit selected value immediately'.

 

2. Rename all your fields so they have sequential naming:

Dropdown1,Dropdown2,Dropdown3...etc

QTY1, QTY2, QTY3...etc

Weight1, Weight2, Weight3...etc

Then you could use one calculation script using a loop to go over all fields.

If you need to manually enter QTY or KG for example I would suggest approach 1.

Votes

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
Community Beginner ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

this code does not work for me. 

function cDrop(qtyField, descField, weightField) {
 var items = {
  "XCR0051": {qty: "1", desc: "24\" CRAWLER CHASSIS FOR ICM", weight: "KG"},
  "PCR2400": {qty: "1", desc: "24CR2 CHASSIS", weight: "61.8"}
//fill the rest of the list here
};

i have supplied a screenshot of the message adobe displays for me below

Charlie303735890y2h_0-1727433327282.png

 

Votes

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
Community Beginner ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

when i use all of the code like below nothing happens for me:

function cDrop(qtyField, descField, weightField) {
 var items = {
  "XCR0051": {qty: "1", desc: "24\" CRAWLER CHASSIS FOR ICM", weight: "KG"},
  "PCR2400": {qty: "1", desc: "24CR2 CHASSIS", weight: "61.8"}
//fill the rest of the list here
};

 var item = items[event.value] || {qty: "1", desc: "", weight: "KG"};

 this.getField(qtyField).value = item.qty;
 this.getField(descField).value = item.desc;
 this.getField(weightField).value = item.weight;
}

 

Votes

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
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Here is your file with changes made (Step 1), first two fields will work, rest you need to fill on your own:

https://drive.google.com/file/d/1QKDb1RA01bM8x7BGNaz89FBPQVPLNUG1/view?usp=sharing 

Votes

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
Community Beginner ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

Charlie303735890y2h_0-1727863426415.pngCharlie303735890y2h_1-1727863434712.png

firstly thank you for the help its amazing.

 

i downloaded the file you sent, as per the screenshots i made a selection from the drop down on every line and nothing happens throughout the whole document. I thought two lines would work but for me they do not. Any feedback is greatly appreciated. 

Votes

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
Community Expert ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

The first two fields work for values "XCR0051" and "PCR2400", the rest of the list you need to fill yourself.

Votes

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
Community Beginner ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

ah okay yes i see it works. How do i get to the document level script part so i can add the rest of the information please? thank you!

Votes

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
Community Expert ,
Oct 02, 2024 Oct 02, 2024

Copy link to clipboard

Copied

Click on tools and select 'Document JavaScript' tool

or

Select 'Prepare form' tool:

press SHIFT+D

or

click 'More' then select 'Document JavaScript'

Votes

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
Community Beginner ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

as a test i just did the next line down which is qty2.3 weight2.3 and description2.3

Charlie303735890y2h_0-1727950304249.png

i then select pcr2400 from the drop down and nothing happens:

Charlie303735890y2h_1-1727950374010.png

the second line is with your code, i then did the same thing ran a custom validation script, edited the text to say 2.3 as per the first screenshot, however it still does not work. am i missing something?

Votes

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
Community Expert ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Your field name is not correct "Description12.3" should be 2.3 not 12.3

Votes

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
Community Beginner ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Sorry. i get what to do now. I will let you know how i get on once i have completed the rest of the document.

 

thanks so much for all the help you have no idea how much you have helped. 

Votes

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
Community Beginner ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Charlie303735890y2h_0-1727959576811.png

i am just checking if i change the names of the qty description and weight fields as the screenshot shows, would the code need to change? surely the only thing that would change is the cDrop("QTY11", "Description11", "Weight11"); would change to cDrop("QTY1", "Description1", "Weight1");

 

is this correct please?

Votes

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
Community Beginner ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Charlie303735890y2h_0-1727959752442.png

here is a bigger sreenshot

Votes

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
Community Beginner ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Charlie303735890y2h_9-1727960235384.png

sorry like this... would the only code that needs to change is the dropdown run a custom validation script cDrop("QTY1", "Description1", "Weight1");

then change the 1 to 2 and so on...?

Votes

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
Community Expert ,
Oct 03, 2024 Oct 03, 2024

Copy link to clipboard

Copied

Yes, just change field names in validation script.

Votes

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