I am thinking about two drop down list, one is depended on another. Both drop down list have values from database. In this case which one is the best way.
-
Retrieve all values from database using plain PHP then store them in javascript variable, later search for second drop down list value (if first drop down list’s value changes)in the javascript (array) variable.
-
If first drop down list’s value changes then retrieve values for second drop down list from database using AJAX(jQuery).
The two alternatives that you’ve indicated has pros and cons, the decision depends on how this pros and cons affects your application:
Pros:
Cons:
Pros:
Cons:
Personally I prefer method 2 if the amount of data is relatively big and the performance is not a must.