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

"Same as above" function

grlintheworld
Registered: Dec 21 2009
Posts: 66

I'm trying to set up a function on my form where the user enters their name and address in a set of fields on section 1 of the form, and then on section 2, they can either enter a different name and address, or check a box that says, "same as above".

When that box is checked, I'd love those fields (in section 2) to fill themselves out automatically based on what the user entered in the set of fields in section 1. I'm able to accomplish this using a great script from a tutorial here on the site, and then just having that button show a duplicated set of fields in section 2 that have the same name as the ones in section 1.

(hope I'm not losing you here)...

The problem though is when you uncheck that box, since both those sets of fields have the same name, they both turn off, instead of just the ones in section 2 like I'd like...

Can anybody help?

Seems like I need to do something like, create a set of fields for section 2 that fill themselves in automatically based on what the user types in section 1, but WITHOUT having the same name so that they don't act the same... Just can't figure out how to do this!

(I'm on a Mac, Acrobat Pro 9.2)

try67
Expert
Registered: Oct 30 2008
Posts: 2398
The script will have no influence if the fields have the same name.
You need to rename one of them, and adjust your script accordingly.

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

grlintheworld
Registered: Dec 21 2009
Posts: 66
I guess my question is though, if I rename the fields, how do I get them to automatically show the same information that was plugged into section 1? This seems to only work if the fields have the same name...
try67
Expert
Registered: Oct 30 2008
Posts: 2398
That's what the script is supposed to do. You check the value of the check box, and if it's checked, you set the value of the fields in section 2 to the value of those in section 1.

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

grlintheworld
Registered: Dec 21 2009
Posts: 66
Is there any way you can help me out with writing that script? I'm new to this and finding the scripting a bit over my head. The script that I currently have in there is

var nHide = event.target.isBoxChecked(0)?display.visible:display.hidden;
this.getField("Inv_Shipping Address").display = nHide;
this.getField("Inv_Shipping City").display = nHide;
this.getField("Inv_ShippingState").display = nHide;

The fields that I'd like these boxes to mimic if the box is checked, are named
save_shipping address
save_shipping city
save_shipping state

THANK YOU! :)
try67
Expert
Registered: Oct 30 2008
Posts: 2398
What should happen to the fields when the box is unchecked?

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

grlintheworld
Registered: Dec 21 2009
Posts: 66
I'd love if they could dissapear. or turn into another set of fields altogether.

let me see if i can explain this better.

i need people to fill in the save_address fields (etc.) no matter what.

then below that are the inv_address fields that they should fill in if they're different from the save_address fields. if they're the SAME as the save_address fields, they should check the box, make the inv_address fields disappear, and then have a new set of fields appear that are identical to the save_address fields. Then if they change their minds, they can uncheck the box, and those inv_ address fields appear again, and the ditto fields that mimic the save_fields disappear.

(sorry if i'm confusing you - it's hard to describe!)
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I'm not sure I followed you completely... It seems to me there are three sets of fields you're talking about. Anyway, here's the code I came up with for what I did understand. It's basically a variant of the code you posted earlier, only more readable in my opinion.
if (event.target.isBoxChecked(0)) {// set visibility to visiblethis.getField("Inv_Shipping Address").display = display.visible;this.getField("Inv_Shipping City").display = display.visible;this.getField("Inv_ShippingState").display = display.visible; // set valuesthis.getField("Inv_Shipping Address").value = this.getField("save_shipping address").value;this.getField("Inv_Shipping City").value = this.getField("save_shipping city").value;this.getField("Inv_ShippingState").value = this.getField("save_shipping state").value; } else {// set visibility to hiddenthis.getField("Inv_Shipping Address").display = display.hidden;this.getField("Inv_Shipping City").display = display.hidden;this.getField("Inv_ShippingState").display = display.hidden; // reset valuesthis.getField("Inv_Shipping Address").value = "";this.getField("Inv_Shipping City").value = "";this.getField("Inv_ShippingState").value = ""; }

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

grlintheworld
Registered: Dec 21 2009
Posts: 66
Thank you, Try67! I'm gonna try this out right now and I'll let you know how it works. I really appreciate this!
grlintheworld
Registered: Dec 21 2009
Posts: 66
(and yes, I guess there are 3 sets of fields that I need to work with. the save_ fields, the inv_ fields, and then the fields that mimic the save_ fields. Does this affect the script that you wrote?)
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Yes. You will need to adjust the names of (some of) the fields for your purposes. I understood that there were only two sets of fields when I wrote the code.

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

grlintheworld
Registered: Dec 21 2009
Posts: 66
ok, i will have a go at figuring this out. thanks again for your help!
grlintheworld
Registered: Dec 21 2009
Posts: 66
this worked brilliantly! and i was able to deal with that third set of fields by just having them show/hide with a second java script on that same button. THANK YOU SO MUCH FOR YOUR HELP! you've just saved me hours worth of agony! :)