Is it possible to set a default value for an address field? I know it's not native to Forms, but perhaps through some JavaScript? I have a process that begins with a cover sheet that determines which forms (in this case, pages) are going to be required for them to fill out. Instead of having them include their personal information on every single form, I designed one Personal Information page for them to fill it out once on, and then it will autopopulate everywhere else. This works great for First, Middle, Last, Phone, SSN, etc., just not Address.
Any thoughts?
Question
Question
Setting the Default Value of an Address Field Equal to Another Address Field
Answer
You are able to set the fields in an address block. I'll give an example that uses a checkbox to trigger the change. The checkbox needs the class .sameAddress. Then also give each address block appropriate classes like .addressMailing and .physicalAddress and then use the following to set the values:
$('.sameAddress').change(setMailingAddress); $('.physicalAddress .Country').val('USA'); $('.addressMailing .Country').val('USA'); function setMailingAddress(){ //console.log('SameAddress checkbox changed.'); if ($('.sameAddress input').is(":checked")){ console.log('Setting Mailing Address the same as Physical Address.'); $('.addressMailing .Address1').val($('.physicalAddress .Address1').val()); $('.addressMailing .Address2').val($('.physicalAddress .Address2').val()); $('.addressMailing .City').val($('.physicalAddress .City').val()); $('.addressMailing .State').val($('.physicalAddress .State').val()); $('.addressMailing .Postal').val($('.physicalAddress .Postal').val()); $('.addressMailing .Country').val($('.physicalAddress .Country').val()); } else { console.log('Clearing Mailing Address.'); $('.addressMailing .Address1').val(''); $('.addressMailing .Address2').val(''); $('.addressMailing .City').val(''); $('.addressMailing .State').val(''); $('.addressMailing .Postal').val(''); $('.addressMailing .Country').val('USA'); } }
This is beautiful. Thank you so much Elexis! I'll try this on my next form I build that utilizes addresses. I anticipate this will work elexcellently ;) Have a great rest of your day and thanks once again!
Yeah, nice work, Elexis. Re-reading this, I think I answered a slightly different question than was asked. Sorry, Dylan.
My answer was geared at doing data lookups into an address field since the built-in address field still doesn't support that.
Replies
You're probably better off creating your own address field with single line fields, then use CSS to lay them out like the default Address.
If you'll have numerous addresses spread across the same process, you might try putting them into a collection so that you can easily duplicate the collection rather than having to duplicate/recreate each of the fields that make up your custom address.
Sometimes the best answer is the simplest one, haha. Thanks Pieter! I'll give that a shot and see how close I can get to replicating the address fields individually.
Edit: Yep, that did indeed work exactly how I wanted it to! Top half is the address field, bottom half is 6 single line fields:
Thanks again Pieter!