CF Muse Reader Asks:
I am trying to develop 3 drop down list boxes which gets the data from the database. On change of first will pop up second and on change of second will get the values based on first and second. Do you know the smartest way to do this. How can I run queries from JavaScript?
The first thing to decide is, do you really want to connect to the server for each change in the drop down box? The answer depends on the size and schema of the database.
If what you are trying to do encapsulates typical drill down functionality and the dataset is small you might consider using cf_threeselectsrelated (see this page near the bottom). It loads up all the data into JS arrays and then sorts through the data based on your selections. For example, if your first box was country and you chose "USA" the second box would suddenly contain "States". Selecting California would cause the filter to trigger for the third box which would now contain cities - and so on. The draw back for this tag is that it doesn't scale well. A really large dataset or a data set where you cannot easily join all the items into a single query won't behave as expected.
The Cfajax project gives you custom tags, CFC's and several samples that mimic the behavior you are looking for. Ajax relies on JavaScript and the "XMLHttpRequest" client object to make requests back to the server. The server (in the case of Cfajax) returns XML which is deserialized into an object and used to load your drop down box (or whatever else you have in mind). The drawback to Ajax is the heavy dependence on JavaScript. For example, the Cfajax tag requires 3 js files to be sourced on each page using ajax.
This approach as the advantage of the most potential for visual appeal because flash is a much better visual medium than HTML. Using Actionscript you would create listener objects that fire back to a CFC on the server and populate your drop downs based on user interaction. The drawbacks to this approach are that the programming skills needed are different, Flash is required (although this is marginally no more problematic than requiring JavaScript) and setting up remoting is more complicated. Obviously you could alleviate that last point by using a web service rather than an AMA (pure remoting) call.
Of the choices presented I rather like Ajax for this one. I hope this helps - happy coding.