Auto Update Form As User Inputs Fields

Hi, I have a form that I would like to auto-update/populate fields based on a uses input into another field. For example, I have a MySQL table with user groups and users. If the user selects a group from the drop down group selection I would like to auto update the users drop down (which starts off with all users) to just include the users of the selected group. If the user selects a user I would like to auto-update the group field. My tables are below.


User Table
-----------------------------------------------
| user_id     | user_name         | group_id  |
-----------------------------------------------
| 1           | Chris             | 1         |
| 2           | John              | 1         |
| 3           | Jim               | 1         |
| 4           | Steve             | 1         |
| 5           | Dennis            | 2         |
| 6           | Brad              | 2         |
| 7           | Jeremy            | 2         |
| 8           | Brian             | 2         |
-----------------------------------------------

Group Table
--------------------------------------
| group_id     | group_name          |
--------------------------------------
| 1            | Managers            |
| 2            | Engineers           |
--------------------------------------

Standard PHP to create the drop down lists I am fine with but I’m not sure how to auto-update or populate the fields as the user makes their way through the form.

Thanks for any help or pointers.

Chris

for this you need to use Javascript, Check out Jquery’s awesome form management tools, written in Javasript for your enjoyment, they have all the solutions you need.
http://www,jquery.com

I use the jquery autocomplete over at the jobs section on Lovelogic.net, it’s a mix of Ajax & PHP querying the database and works rather nicely. Even has a spinny waiting image while running big queries of the database.

If you want to auto-update without a page refresh then you will need AJAX. Here’s a good tutorial.

If you use jquery (which is just javascript btw) you will end up running a lot more javascript in the background than if you build your own ajax functionality.