Expand my Community achievements bar.

SOLVED

***HELP*** Need Script that populates descriptive text in another text field when list item is selected

Avatar

Level 1

I am using adobe Livecycle ES4. I am creating a form for my salespeople in the field to access and enter quotation and order to submit to my office.  I have been trying to figure this out for three days. My main issue is using a dropdown list that has all of my my codes (594), I want the user to select a list value and it populate the fields next to it with the item description in one field then the item price in another. I then want to calculate another cell with qty entered time price. I would like them to be able to access this using mobile devices, tablets or surface type and laptops. New to building forms. I can understand script when directed. I do have the ability to host a file or files if it makes it easier.IMG_0514.jpg

http://geauxwebs.com/wp-content/uploads/2020/04/New-Order-Form-Teststatic.pdf 

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi, 

 

you can realize this with an array of nested arrays and two javascript functions. One is to populate the selectable values in the dropdown list the other to populated the description ond price depending on the selection.

 

First, you need to add a script object to your form. Name it "formFunctions" or whatever you like. 

In this script object you enter the array and the two functions.

 

// Array with data
var aItems = [
	// Nested arrays with item number, description and price
	["123", "Chair", "99.99"],
	["222", "Table", "350.00"],
	["600", "Lamp", "24.90"]
]

// Function to populate item numbers into drop down list
function loadItemNums (oDDL) {
	oDDL.clearItems();
	aItems.forEach(function (aItem) {
		oDDL.addItem(aItem[0]);
	});
}

// Funtion to populate description and price
function loadItemDetails (cSel, oDesc, oPrice) {
    oDesc.rawValue = null;
    oPrice.rawValue = null;
	aItems.forEach(function (aItem) {
		if (aItem[0] === cSel) {
			oDesc.rawValue = aItem[1];
            oPrice.rawValue = aItem[2];
		}
	});
}

 

So then, you only need to call the related function from the enter and change event of the drop down list. 

Enter event:

formFunctions.loadItemNums (this);

 

Change event: Note the fields to be populated in this example are names "Desc" and "Price", you may have to change the namings here.

formFunctions.loadItemDetails (xfa.event.newText, Desc, Price);

 

That's it. 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Hi, 

 

you can realize this with an array of nested arrays and two javascript functions. One is to populate the selectable values in the dropdown list the other to populated the description ond price depending on the selection.

 

First, you need to add a script object to your form. Name it "formFunctions" or whatever you like. 

In this script object you enter the array and the two functions.

 

// Array with data
var aItems = [
	// Nested arrays with item number, description and price
	["123", "Chair", "99.99"],
	["222", "Table", "350.00"],
	["600", "Lamp", "24.90"]
]

// Function to populate item numbers into drop down list
function loadItemNums (oDDL) {
	oDDL.clearItems();
	aItems.forEach(function (aItem) {
		oDDL.addItem(aItem[0]);
	});
}

// Funtion to populate description and price
function loadItemDetails (cSel, oDesc, oPrice) {
    oDesc.rawValue = null;
    oPrice.rawValue = null;
	aItems.forEach(function (aItem) {
		if (aItem[0] === cSel) {
			oDesc.rawValue = aItem[1];
            oPrice.rawValue = aItem[2];
		}
	});
}

 

So then, you only need to call the related function from the enter and change event of the drop down list. 

Enter event:

formFunctions.loadItemNums (this);

 

Change event: Note the fields to be populated in this example are names "Desc" and "Price", you may have to change the namings here.

formFunctions.loadItemDetails (xfa.event.newText, Desc, Price);

 

That's it.