|
Filling out default info on form via Ajax
I have what I would expect to be a common challenge, and yet after hours of searching I can't find where it has been addressed in any kind of Ajax tutorial.
I have a form used by order administrators to enter orders for wholesale customers.
It has store name, contact name, phone, street address, city, state, zip and country fields, among others.
The store name field is a pulldown menu whose options are generated at page load by a php script that pulls them out of a database.
I'd like to implement an Ajax script where, when a store is selected from the pull down menu the page pulls all the contact and address infomation from the database and populates the fields with that information as the default.
Passing the argument to the server is easy enough: I can just make the store name pull down associate the primary key of the stores table with the store name and then pass that back. (As in, <option value="12">Visible Store Name</option>, so that I just pass the 12 back to the script if "Visible Store Name" is chosen from the pull down, and then the server side script pulls all the address info for store #12.
But then how do I get the information to populate the fields? Just printing out the results of the query is easy enough, but I can't figure out how to address the individual values and put them into the value attributes of the fields.
I am an absolute AJAX n00b. This is the first time I've ever even looked at it, and I feel totally lost with it. So any help at all would be greatly appreciated.
Thanks
Wayne
|