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

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

Page 1 of 1

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

#1 kaveran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-January 09

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

Posted 27 January 2009 - 08:32 AM

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.......

Autos - ID 1 - parentID 0
ford - ID 2 - parentID 1
chevy - ID 3 - parentID 1
F150 - ID 4 -parentID 2
4wheel drive - ID5 - parentID 4
2wheel drive - ID6 - parentID 4
1500 - ID7 - parentID 3
4wheel drive - ID8 - parentID 3
2wheel drive - ID9 - parentID 3
boats - ID10 - parentID 0
paddle boats - ID11 - parentID 10
motor boats - ID12 - parentID10

Tree view of the above data

Autos
->ford
->->f150
->->->4wheel drive
->->->2wheel drive
->chevy
->->1500
->->->4wheel drive
->->->2wheel drive
boats
->paddle boats
->motor boats

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?

Is This A Good Question/Topic? 0
  • +

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

#2 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,604
  • Joined: 20-January 09

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

Posted 27 January 2009 - 09:09 AM

This is a little beyond me - but I know that jQuery can work with Ajax and PHP (Although this takes a little work since php is server side and JS is client side).

http://docs.jquery.com/Ajax

--

Greg
Was This Post Helpful? 0
  • +
  • -

#3 kaveran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-January 09

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

Posted 27 January 2009 - 09:14 AM

View Postgregwhitworth, on 27 Jan, 2009 - 08:09 AM, said:

This is a little beyond me - but I know that jQuery can work with Ajax and PHP (Although this takes a little work since php is server side and JS is client side).

http://docs.jquery.com/Ajax

--

Greg


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.

This post has been edited by kaveran: 27 January 2009 - 09:15 AM

Was This Post Helpful? 0
  • +
  • -

#4 rockstar_  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 189
  • Joined: 16-October 06

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

Cheers!
Was This Post Helpful? 0
  • +
  • -

#5 kaveran  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-January 09

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

Posted 27 January 2009 - 02:11 PM

View Postrockstar_, 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1