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

Multi value, multiple options - how to auto-populate?

Mel2410
Registered: Oct 17 2011
Posts: 10

Hi,
I'm working on an order form and I have some scripting that I can't figure out how to make work. I need to be able to have a customer choose per item from 1-4 colors, enter a quantity, and then based on the number of colors chosen and the quantity ordered, have the form auto-populate with the correct price points (price points change based on the number of items ordered AND the number of colors). For example, they could choose:
 
1 color, less than 500 qty = price 1
1 color, between 500 and 1,000 qty = price 2
1 color more than 2500 qty = price 3
 
2 color, less than 500 qty = price 4
2 color, between 500 and 1000 qty = price 5
2 color more than 2500 = price 6
 
etc., etc. up to 4 colors. I can get the form to work when it's just 1 color using a script like this:
 
var v1 = +getField("qtyWhite_1").value; if (v1 < 500) event.value = 2.30;if (v1 >= 500 && v1 < 1000) event.value=2.25;if (v1 >= 2500) event.value = 2.20;
 
But I can't figure out how to make it work if the customer chooses 2, 3 or 4 colors of the same item and have that reflect in the unit price. Any advice? The fields I have to work with are "Quantity", "1 Color", "2 Color", "3 Color", "4 Color", "Unit Price", and "Total". Do I need rearrange the fields and/or combine the colors to make this work?
 
Thanks

My Product Information:
Acrobat Pro 9.4.3, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
How is the color selection happening? Is it with radio-buttons, a drop-down, or something else?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
I can set up the color selection to happen in whatever way lends itself best to the form, but right now it's set up as a drop down menu.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
So you need to do a two-tier system, first check the color selection, and then inside of each option you do another check for the quantity. So it will look something like this:

var colorSelection = this.getField("Color").value;
if (colorSelection=="1") {
// do the checks for the first color
} else if (colorSelection=="2") {
// do the checks for the second color
}
etc.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
That makes sense, thanks. Since I'm still new to javascripting, where exactly would I place the code to check the quantity and subsequent pricing for each color, after "if (colorSelection=="1")"?

Thanks for your help!
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Yes, inside the curly brackets after the if-statement. I've used the values "1", "2", etc. as an example. You need to adjust them to the actual values of your combo-box, of course.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
I must be missing something yet, this is what I have so far, but it's not working yet:

var colorSelection = this.getField("Colors").value;
if (colorSelection=="One Color") { if (v1 < 500) event.value = 2.30;if (v1 >= 500 && v1 < 1000) event.value=2.25;if (v1 >= 2500) event.value = 2.20;//
} else if (colorSelection=="Two Colors") {
// if (v1 < 500) event.value = 2.40;if (v1 >= 500 && v1 < 1000) event.value=2.35;if (v1 >= 2500) event.value = 2.30;
}

Where did I go wrong?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The "//" marks the start of a comment, so the text in that line will not be executed. You need to remove those symbols from your code.

Also, be more specific. Doesn't work *how*? Are there error messages in the JS console?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
It doesn't work as in when I choose a color, and plug in a quantity, nothing appears in the unit price field. All that changes is my "Colors" field, which is changing from one color to say 2.3 (or 2.4 depending on if I chose one color or two). No error messages on the JS console.
Mel2410
Registered: Oct 17 2011
Posts: 10
Strike that, I got it to work a bit more, but it's only pulling up the first pricing option for each color choice, I can't get it to auto-populate with the lower price points as the quantities increase. It's almost there! :-)
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Post your full code, please.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
Here is the full code that is applied to my "unit Price" field. I've only done the first two colors right now until I get those working, then I'll add the additional 2:

var colorSelection = this.getField("Colors").value;
if (colorSelection=="One Color") { if (v1 < 500) event.value = 2.30;if (v1 >= 500 && v1 < 1000) event.value=2.25;if (v1 >= 2500) event.value = 2.20;
} else if (colorSelection=="Two Colors") {
if (v1 < 500) event.value = 2.40;if (v1 >= 500 && v1 < 1000) event.value=2.35;if (v1 >= 2500) event.value = 2.30;
}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Where are you defining "v1"?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
Ahh....perhaps that is the problem, I missed that step. Do I write that "v1" = a drop down choice from my "Colors" Field, like this:

var v1 = this.getField("Colors Dropdown_1").value;




try67
Expert
Registered: Oct 30 2008
Posts: 2398
I thought that was the "quantity" value... "Colors Dropdown_1" is probably the name of the field that corresponds with colorSelection.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
No, the quantity value is a separate field not linked to the "Colors" field. If it's easier, I can just email you the actual PDF I'm working with?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Sure, no problem.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Mel2410
Registered: Oct 17 2011
Posts: 10
Just sent it - thanks again! :-)