G
groups2
I am fixing up a site where the address data for all the addresses for
each customer is called with 1 query and then added to a javascript
array. The street name of each shipping addresses is available in a
dropdown menu. When an address is chosen, the details are displayed
for editing in input fields under the menu.
The addresses are either US , international or military addresses.
Most of the fields are common to all types of addresses, buy each type
of address also has some unique fields. When the address is chosen, I
want only the relevant fields to display.
Option 1: The site originally had all the fields on each page no
matter which type of address was selected. Each field was made
visible or invisible as needed with javascript, but this left empty
spaces where the unused fields were.
Option 2: I could create the unique fields with ajax, and then fill
them in with data from the address array. I tried this, and it seems
like the script tries to validate the fields before they are created,
even if the validation comes after the ajax call. I don't like the
idea of using a timer, so is there any other way to have the script
wait until the ajax section is done before proceeding ?
Option 3: I could call only the address ids and street names when the
page loads, and then use ajax to call and display the address data for
each address when the user chooses it. This means a query for each
address, but that doesn't seem like a big deal.
Option 4:I could forget ajax calls entirely and use javascript to
construct and delete only the unique input fields as they are needed.
This seems javascript heavy, but it works fine and I'm leaning in this
direction.
What's the right way to do this ?
each customer is called with 1 query and then added to a javascript
array. The street name of each shipping addresses is available in a
dropdown menu. When an address is chosen, the details are displayed
for editing in input fields under the menu.
The addresses are either US , international or military addresses.
Most of the fields are common to all types of addresses, buy each type
of address also has some unique fields. When the address is chosen, I
want only the relevant fields to display.
Option 1: The site originally had all the fields on each page no
matter which type of address was selected. Each field was made
visible or invisible as needed with javascript, but this left empty
spaces where the unused fields were.
Option 2: I could create the unique fields with ajax, and then fill
them in with data from the address array. I tried this, and it seems
like the script tries to validate the fields before they are created,
even if the validation comes after the ajax call. I don't like the
idea of using a timer, so is there any other way to have the script
wait until the ajax section is done before proceeding ?
Option 3: I could call only the address ids and street names when the
page loads, and then use ajax to call and display the address data for
each address when the user chooses it. This means a query for each
address, but that doesn't seem like a big deal.
Option 4:I could forget ajax calls entirely and use javascript to
construct and delete only the unique input fields as they are needed.
This seems javascript heavy, but it works fine and I'm leaning in this
direction.
What's the right way to do this ?