to ajax or not

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 ?
 
G

Gary Hasler

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 ?

Well, I can't say this is the right way, but wouldn't Option 1 work if
you use "display:none" to hide the irrelevant items? They wouldn't take
up space in the layout.
 
G

groups2

Well, I can't say this is the right way, but wouldn't Option 1 work if
you use "display:none" to hide the irrelevant items? They wouldn't take
up space in the layout.

You know what? I think that is the best overall method. Thanks for the
tip!
If I had thought of that I probably wouldn't have thought of all the
other methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,801
Messages
2,569,659
Members
45,427
Latest member
Fredrick95

Latest Threads

Top