how to "link" two drop-down lists with php, javascript, mysql? -


i want create form 2 drop-down lists (country , town), filled options 2 mysql tables. , second list (towns) populated options depending on value of selected option on first list (country).

i know how load options php , mysql countries list , can link second list populated options javascript. there conditionals in script updates values of second list. need mysql query second list. how can start second query when page loaded?

you've got 2 general ways of going this.

first, include of values page possibly javascript array, first list changed, re-adds appropriate values second drop-down. if use method, every item (from both tables/lists) loaded on every request. if total number of items relatively small (say <100) best approach.

the other option issue ajax request after first dropdown selected. request contain id/value of dropdown, , return items valid value. method means need 1 query on initial page load (the values first dropdown) requires create javascript handler.

i've seen both approaches used. first 1 better smaller datasets, can faster since query static (no parameters), , can cached. however, transmit data on every request. second 1 "cleaner" requires @ least 1 ajax request. if familiar using approach best option.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -