Dynamic Form Help

Hey guys, here is my problem. I have two tables in a database (table A and table B). I’m trying to create a form where values from table A dynamically populate a select list (I can do this). Then depending on what they pick the rest of the form loads up based on values from table B. For example:

The user selects “lunch” from the drop down list (populated by table A); then the rest of the form populates with options from table B that correspond to “lunch”. I can do this easily by making the form 2 pages, but I am hoping to do it on one page. Thanks for any help!

I’ll get a little more in detail just to help clarify. I know I’m going to probably have to use Javascript or AJAX for this (which I know almost nothing about). Here is the situation:

Database
TABLE A (ID, Name, Description, Active)
TABLE B (ID, Name, Description, A_ID, Active)

So with the drop down on the form I choose an option with an ID of 2. Then I would like the rest of the form to populate with data from Table B that has an A_ID of 2.

yes, it can be done.

what I have done in the past is have a hidden iframe that goes and runs the php to get the results of the selection, then use javascript to get the results from a named form field or text area in the hidden frame. you can then fill in a field or cell on your active page.

if you name the iframe ifr1 and you have a form field named fred, you get it with:

document.getElementById(‘ifr1’).contentWindow.document.getElementById(‘fred’).value

if the form in the iframe is named ic1, use the following to make it submit.
document.getElementById(‘ifr1’).contentWindow.document.getElementById(‘ic1’).submit();

hopefully you can go from there.

another (lame) way of doing it is prefill everything and use style commands to hide and unhide the info you want.

I think the best solution to this problem is making a JavaScript array containing all possibilities for the second select element, and then fill the actual element with the values from this array that correspond with the selection from the first select element.

Sponsor our Newsletter | Privacy Policy | Terms of Service