You are viewing limited content. For full access, please sign in.

Question

Question

"State" Field Not Automatically Filled When Duplicating Address Field by Checkbox

asked on August 10, 2017

Since there are many instances that forms will require two address fields and the address fields will frequently match (e.g., mailing address and street address, shipping address and billing address, etc.), it may be more efficient to duplicate the address field by checking a box.  As you can see from the screenshot, all of the street address fields are automatically filled with the specified mailing address, except for the state field, which has been modified for a drop-down list for the state information.

Below is the code that modifies the state field and automatically fills the street address fields.  Any ideas why the state field is not being filled and how the code should be changed?

Duplicating Address Field by Checking a Box.PNG
JavaScript for Duplicating Address Field by Checkbox.PNG
0 0

Answer

SELECTED ANSWER
replied on August 10, 2017

Hi John,

Since you have changed the State field from "input" element to "select" element, $('.MailingAddress').find('input') will not find this field, so it is not updated.

Find select element and update its value:

$('.StreetAddress').find('select').val($('.MailingAddress').find('select').val());

 

0 0

Replies

replied on August 14, 2017

Thanks, Rui.  That worked!  Below is the entire code that automatically fills in the "Street Address" when the box is checked along with a screenshot of the two address fields.

JavaScript for Automatically Filled Address Fields.PNG
Automatically Filled Street Address.PNG
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.