These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Linking combo field choice to variable price item

tomt491
Registered: Nov 19 2008
Posts: 23
Answered

Thanks to "Merlin" and "George" for helping me with my previous problems with a merchandise ordering form. I'm trying a different approach to make the process even more functional. I'm using Acrobat 5 that I've updated recently to Ver 5.010.

Here's a link to another version of the ordering form.....

http://cid-574cab0dff9f00f2.skydrive.live.com/browse.aspx/Acrobat%205%20Questions?uc=1

In this one, I have opted to use a combo box to allow the buyer to make a choice between "s, m, l, xl, xxl and xxxl" items. They then move to the next field and enter a quantity. What I would like to have happen, if it's even possible in Acrobat 5 is to have the program automatically input the correct price for the selected combo item in the Price field.

When that's done, I know how to use the Calculation options to compute the Item Total for that particular line.

I'm assuming that some sort of Acrobat javascript is necessary to make this happen, but I don't have any experience writing that code.

Do any of you in this group know if this is possible and, if so, what would that coding be?

Thanks again for your help.
Tomt491

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Normally one would have a catalog with a item price and quantity specified and one would need to compute just the price times the quantity. But in your situation you want to have the price determined by the size. With a combo box or list box there is a "Item" and "Export Value" on the "Options" tab for the field's property. If the "Export Value" is empty then the "Item" becomes the value for that field, but if there is value in the "Export" that becomes the value of the field.

So if you assign an export value to each size, you only need to set the value of the price field to the value of the size field. The simplest computation would be done with the calculation option of "The is the Sum of:" and select the size field. And then for the "Item Total" field you only need to select the "Price" and "Quantity" fields for computing the quantity. Because you chose to have the currency sign appear, if you want the zero price and subtotals not to show you would need to add a validation script to hide the field when the value is zero with the following custom validation script for the price and subtotals for the item 1 fields:

this.getField(event.target.name).display = display.visible;
if(this.getField("size item1").value == 0) this.getField(event.target.name).display = display.hidden;

You would need to the "size item1" to "size item2" for the item 2 fields.

To find out more about JavaScirpt, you might want to look at Thom Parkers JavaScript Corner.

George Kaiser

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You will need to use a bit of JavaScript, and there are a number of approaches you can take, so it's certainly possible. The basic problem is associating a price with the items in the two list boxes. You can do this several ways, including hardcoding the prices in a script or setting up a variable (object) that associates the items with a price so that you can easily look up the price given the style and size. The latter approach is easier to maintain is is less error prone. The following article by Thom Parker doesn't cover exactly what you're doing, but it will introduce you to the general ideas:
http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle/

Then next thing to decide is where to place the code to set the price field value. This could be implemented as a custom calculation script for the price field or as a script that gets called in the Validate (or Keystroke) events of the Style and Size combo boxes. The latter is harder to explain but is what I would prefer for the best performance and other reasons.

For the calculation script approach, the code would get the value of both the Style and Size fields, make sure that both have valid selections, look up the corresponding price, and set the field value to the price. If there is not a valid Style and Size selected, then set the field value to nothing.

For the validation script approach is a bit more complicated, so I won't get into it for now. If you get stuck, post again.

George
tomt491
Registered: Nov 19 2008
Posts: 23
George and Gkaiseril,

Thanks for your tips and advice. I took the easy route and used the Export Value option rather than getting involved with javascript.

Here is a link to the sample form I was discussing.

http://cid-574cab0dff9f00f2.skydrive.live.com/self.aspx/Acrobat%205%20Questions/conventionmerchandiseshirtcomboboxfillin.pdf

It's kind of a long URL, so I hope it still works.

Thanks to both of you for helping an Acrobat novice. I really appreciate your assistance.

Tomt491
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Looks good. You might consider limiting the quantity to a reasonable range (0-100), or at least positive numbers. As is, you can enter negative numbers and very large ones. Also, calculated fields should be set to read-only so the user cannot attempt to interact with them. They should not be able to receive the focus.

For future projects, be aware that when you set the export values of list items, if the export values are not unique, the user interface when setting/modifying the items behaves oddly. For example, go back and try to adjust the export value for the Medium size. I don't recall if this is a problem for version 5, but it is for 6-9 at least.

Much worse though is if you have to programmatically set the field value or import the form data back into the form. There is no way to control which item that shares the same export value will be selected.

If you were to set up this form to submit the form data, there would be no way for you to know which style & size was selected since the export value is the price of the item, and several items share the same price.George
tomt491
Registered: Nov 19 2008
Posts: 23
George,

Good point about setting a range in the Quantity fields and making all the calculated fields Read Only. As I was working on the form, I did notice what you said about trying to change the Export Value settings. While I could change the entry, there was no way to save the changed version. The only way I could do it was to re-enter the entire value and delete the previous entry. Since I probably won't have many Order Item lines, changing all of them for each line won't be a problem, because I'll just change one and copy it to the other lines.

Thanks again for your help.

tomt491