How can I refresh a databound dropdown list without refreshing the whole page?
I've created a insert and update form for a PRODUCTS table using PHP and MySQL.
Each form contains a, databound, SELECT field that queries a COMPANIES table to populate.
The record ID, of each company, is used in the PRODUCTS table to group products by company.
I need to find a way to allow users to add new companies while adding products.
I want the user to be able to select 'Add New' from the dropdown and trigger a lightbox containing the 'Add company' form. They would add the their company name submit that form and the lightbox would close. That would trigger a refresh of the COMPAN开发者_开发技巧IES dropdown and select the passed value.
That's how I see it. Not sure if it's the best UX but I need some help. I kneed to know:
1. how to trigger the lightbox from an OPTION in the SELECT field.
2. how to place the Add Companies form in the lightbox. 3. how to refresh the COMPANIES SELECT field, on the original form, with the new value. While retaining any previously entered values in other fields.Any suggestions are greatly appreciated.
Cheers
DougPseuo-code:
- Load up your companies list (as you do)
- Bind to the "change" event on the company drop down (same as you do with updating products based on the selected company). When the select's value equals your "Add new company" value, trigger the light box.
- Light box form would use an AJAX call to a script (in the background) that would add the new company (I would also implement some error checking/validation).
- When a successful response comes back from AJAX, add the new company to the select list, select it, and then the value change should re-trigger your product drop-down to switch.
All-in-all, it should be pretty simple.
精彩评论