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
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
September 10, 2024

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