Skip to main content
Known Participant
September 10, 2024
Answered

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

  • September 10, 2024
  • 1 reply
  • 8335 views

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!

This topic has been closed for replies.
Correct answer Nesa Nurani

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;
}

 


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 

1 reply

Nesa Nurani
Community Expert
Community Expert
September 10, 2024

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

Known Participant
September 10, 2024

 

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!
Nesa Nurani
Community Expert
Community Expert
September 10, 2024

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!


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.