4 Replies - 2455 Views - Last Post: 27 January 2009 - 02:11 PM

is jquery the right tool for the job? (ajax)

Im a php coder and new to the world of javascript and I am wondering if someone familiar with jquery can tell me if it would be the right tool for task I would like to undertake.

In short, what I have is a database table that contains a list of items. Each item in the database table has an ID field and a parent ID field. This means that each record is either a top level item or a child item to an existing item in the table.

Using php I query the database and collect all the top level items (ie everything with a parent ID of 0) and present this to the user in an html dropdown.

Using a simple jquery ajax call the id of the selected item is handed out to another php script which does another database query and collects all the items that have a parent ID equal to the one chose in the initial dropdown presented to the user and in turn build another dropdown that is presented to the user.

The above works well but I am in a situation where there may be additional levels under those presented by the ajax built dropdown but being new to javascript and jquery I cant quite figure out if or how I can basically have created nested ajax dropdowns.

To further clarify here is an fictional example of the data I am working with.......

My default page creates a dropdown with the options Autos and Boats. When I select autos I have jquery ajax calling another php function that returns a dropdown in a div just below my original dropdown with ford and chevy opions and that is as far as I can get. Of course changing it from autos to boats would yield a div refresh and the dynamic dropdown contents would change from ford and chevy to padle boats and motor boats but I cant seem to figure out how to use jquery to get any deeper.

Can I easily use jquery to further create dynamic nested dropdowns of (theoretic) unlimited depth? If so does anyone have a link to a related tutorial, blog post etc that may help?

Thanks for the link, ive spent quite a bit of time there already. Im new to javascript in general so diving in a bit faster than I normally would. I have the php part and database access etc all down, not worried about that. I actually have jquery and ajax working but can only get a single dynaic dropdown of the 1st level under the parent level. I cant seem to figure out how to have my dynamically created dropdown rerun the JS/ajax which in turn will run my php function and collect data to build yet more dropdowns.

Re: is jquery the right tool for the job? (ajax)

Posted 27 January 2009 - 01:25 PM

If you're wanting to create tables that sort and such using jquery, I strongly suggest using jQuery UI, which will provide widgets for sortable tables, etc. I've used jquery and jquery ui in many projects, and I find it to be the better of the js/ajax/ui libraries. Jquery ui can be downloaded from http://ui.jquery.com

Re: is jquery the right tool for the job? (ajax)

Posted 27 January 2009 - 02:11 PM

rockstar_, on 27 Jan, 2009 - 12:25 PM, said:

If you're wanting to create tables that sort and such using jquery, I strongly suggest using jQuery UI, which will provide widgets for sortable tables, etc. I've used jquery and jquery ui in many projects, and I find it to be the better of the js/ajax/ui libraries. Jquery ui can be downloaded from http://ui.jquery.com

Cheers!

Nope, I dont want to create tables at all.

All I want to do is create dropdowns based off of table data. The above data was just to help people understand my question and goal.

The problem I am having is that I have potentially an unlimited number of dropdowns that need to be created.

a php function queries my data table and creates a dropdown with all of the top level items (ie items with no parent ID).

A user selects one of those dropdown options and jquery/ajax creates another dropdown that contains all of the database items that have a parent ID that matches what the user selected in the initial dropdown.

Ive got it working up to that point but am having trouble building yet another dropdown of children to the last dynamically created dropdown etc etc. Ive searched the web for hours but it seems that every other site all just links to the same couple examples etc.