PDA

View Full Version : Need help with updating entries automatically...


ViN86
05-25-07, 03:48 PM
right now i have two <select> items on a webpage. one represents companies and one represents projects.

the projects depend on which company is selected. how can i make the project dropdown box change automatically when the company dropdox box is changed?

i am working in PHP and am open to java suggestions. thx.

Sazar
05-25-07, 03:57 PM
Do you have a lookup table?

/me is thinking in terms of sql.

If so, you SHOULD be able to have updated data on the drop-down menu depending on what the table's contents consist of.

ViN86
05-25-07, 03:59 PM
Do you have a lookup table?

/me is thinking in terms of sql.

If so, you SHOULD be able to have updated data on the drop-down menu depending on what the table's contents consist of.
yes im using mysql to retrieve the companies and projects (projects are linked to the companies table).

im referring more to actually updating the projects list when the company list item is changed.

say i have companies:

A with projects 1,2,3
B with projects 4,5,6
C with projects 7,8,9

A is initially set and projects 1,2,3 are displayed. i want the project list to be changed to 4,5,6 as soon as the company list is changed to B. how would i do that?

fivefeet8
05-25-07, 04:16 PM
right now i have two <select> items on a webpage. one represents companies and one represents projects.

the projects depend on which company is selected. how can i make the project dropdown box change automatically when the company dropdox box is changed?

i am working in PHP and am open to java suggestions. thx.

PHP is a server side language. To make any changes appear on the page requires a refresh with updated data.

If you want the list to change without refreshing, you will need to use is either Javascript/Java to modify the HTML DOM select items you have on your page when an onChange event happens on the Company select box. There are many ways this can be done with Javascript.

The issue is, the data is located on the server and would require:

a: Data needs to be available to the javascript upon page load.
b: Data can be pulled from the database asyncronously(AJAX).

If you don't want to go the javascript route, you could post the page back onto itself everytime you select a different company from the list. The post data would contain the currently selected company and your php script can then use that POST data to fill the projects list. You could also try using a session variable to store the currently selected company. Of course this means everytime you select a different company from the list, the page reloads.

ViN86
05-26-07, 10:09 AM
i figured out how to do it.

i added an "onchange" event that linked to a javascript function. the function was called with the value of the newly selected item (the variable this.value was passed to the function which just directed to a new page, which was the value of the select option). for each item, the value was set to the same page with a GET method.

so the link was:
pagename.php?company=selectedcompanyname

then i used a $_GET['company'] call in PHP to get the value and set the selected item

If you don't want to go the javascript route, you could post the page back onto itself everytime you select a different company from the list. The post data would contain the currently selected company and your php script can then use that POST data to fill the projects list. You could also try using a session variable to store the currently selected company. Of course this means everytime you select a different company from the list, the page reloads.
yes, this is what i did pretty much ;)
thx.