Clicky

I have a drop menu and the content in the drop menu is pulled from a MySQL database.

I also have a list of printers on my page which is also pulled from a MySQL database. I would like the list of printers to update based on the value in the drop menu.

I understand how to do using php and reloading the page, however I would like to do it using jquery so there is no need to reload the page.

I'm not sure how to do this can you please show me an example?

asked 12/14/2011 11:38

petewinter's gravatar image

petewinter ♦♦


2 Answers:
so create a php page called get_printer_list.php or similar, the only thing this page should do is take a parameter, run a query to your database to get the printers that match the parameter and then loop through the result and echo it to the page in either xml or json format.

You will call the above page in your ajax action, passing it the parameter that will return the correct result for whatever was selected in your first drop down menu.

In the success function of the ajax call you would remove all current items from the printer dropdown and then parse the xml/json you received back from the ajax call and populate the printers dropdown with that information.


so first drop down box, onchange calls a function that makes the ajax call.
ajax returns and calls it's success function
the success function deletes all items from the printers drop down, reads the result of the ajax call and puts that into the new combobox.

found a good resource with code examples, don't want to repost someone elses work and why recreate the wheel:

http://www.joe-stevens.com/2010/02/23/populate-a-select-dropdown-list-using-jquery-and-ajax/
link

answered

jrm213jrm213's gravatar image

jrm213jrm213

Thanks for your help
link

answered 2011-12-15 at 08:35:25

petewinter's gravatar image

petewinter

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×15
×125
×63

Asked: 12/14/2011 11:38

Seen: 325 times

Last updated: 12/15/2011 06:14