Road Closed

This information is outdated and is no longer maintained. Get the latest!

 

Can I validate two addresses in a single form?

Question

Last Updated: March 18, 2013

I have billing and shipping address in single form and i want to implement the address validation code: My questions are: 1. I am using javascript implementation. is this correct? 2. how can i have 2 separate fields set for address validation one for billing address and another for shipping address.

In this case it will be making two requests to liveaddress. Is it possible, before it makes the second request, for me to compare the shipping and billing addresses and only submit the second request if they are different?

Answer

Great question. The javascript implementation does indeed support multiple addresses per page. Here's a sample that shows how to configure the QadApi object to verify 2 addresses that are each on the page:

QadApi
(
    {
        key: YOUR_KEY_HERE,
        timeout: 10,
        busySubmit: false,
    },
    {
        busyId: "QadBusy",
        addresses: 2, // the number of menus to display simultaneously
    },
    [
        // primary address elements (required)
        {   name: "Billing Address", // required
            street: "textBillStreetId", // required
            street2: "textBillStreet2Id", // optional
            unit: "textBillUnitId", // optional
            city: "textBillCityId", // required with state
            state: "listBillStateId", // required with city
            zip: "textBillZipId", // required (instead of or in addition to city/state).
            country: "listBillCountryId" // optional
        },

        // secondary address elements (optional)
        {   name: "Shipping Address", // required
            street: "textShipStreetId", // required
            street2: "textShipStreet2Id", // optional
            unit: "textShipUnitId", // optional
            city: "textShipCityId", // required with state
            state: "listShipStateId", // required with city
            zip: "textShipZipId", // required (instead of or in addition to city/state).
            country: "listShipCountryId" // optional
        }
    ]
);

So, just make sure you include the 'addresses: 2' setting and that the IDs of the address form elements match up with the correct address fields (billing vs. shipping).

The Javascript actually already handles this situation. If the two addresses are identical (not considering small white-space differences) the API only submits one request and only shows one set of matches.