Copy link to clipboard
Copied
i have a drop down with this code:
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!
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.
Copy link to clipboard
Copied
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:
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?
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!
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.
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.
Copy link to clipboard
Copied
Read these articles:
https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations/
https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm
https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm
Copy link to clipboard
Copied
Can you share your file so I can see what is going on?
Copy link to clipboard
Copied
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.
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
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; }
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
Copy link to clipboard
Copied
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.
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.
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!
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'
Copy link to clipboard
Copied
as a test i just did the next line down which is qty2.3 weight2.3 and description2.3
i then select pcr2400 from the drop down and nothing happens:
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?
Copy link to clipboard
Copied
Your field name is not correct "Description12.3" should be 2.3 not 12.3
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
here is a bigger sreenshot
Copy link to clipboard
Copied
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...?
Copy link to clipboard
Copied
Yes, just change field names in validation script.