Page 1 of 1

One valuelist depending on another valuelist's selection

PostPosted: Wed Jul 15, 2009 12:52 pm
by tomhousley
Hello,

I have 3 tables, one for organisations, individuals and invoices and I would like to create a single table to make notes about the above as and when I need to.

The relevant tables are:

tbl_organisations
tbl_individual
tbl_invoice

the history table is called tbl_ history, the contents of which are:

Code: Select all
his_id           INT(6)    (NULL)           NO      PRI     (NULL)   AUTO_INCREMENT  SELECT,INSERT,UPDATE         
his_parentid     INT(6)    (NULL)           NO      MUL     (NULL)                   SELECT,INSERT,UPDATE         
his_parenttable  INT(6)    (NULL)           NO              (NULL)                   SELECT,INSERT,UPDATE         
his_notes        TEXT      utf8_general_ci  NO              (NULL)                   SELECT,INSERT,UPDATE         
his_enteredby    INT(6)    (NULL)           NO              (NULL)                   SELECT,INSERT,UPDATE         
his_dateandtime  DATETIME  (NULL)           NO              (NULL)                   SELECT,INSERT,UPDATE     



I have a fifth table which lists the names of the tables:

Code: Select all
tbl_id             INT(6)     (NULL)             NO      PRI     (NULL)   AUTO_INCREMENT  SELECT,INSERT,UPDATE         
tbl_name           CHAR(255)  latin1_swedish_ci  NO              (NULL)                   SELECT,INSERT,UPDATE         
tbl_description    CHAR(255)  latin1_swedish_ci  NO              (NULL)                   SELECT,INSERT,UPDATE         
tbl_showinhistory  BINARY(1)  (NULL)             NO              (NULL)                   SELECT,INSERT,UPDATE       



The /tbl_history/valuelists.ini file contains the following:

Code: Select all
[his_parenttable]
__sql__ = "SELECT tbl_id, tbl_description FROM tbl_tables ORDER BY tbl_description"


The question is, when i create a new history record and I select the tbl_organisation, i would like this to then change the contents of the drop down below it to only show names of organisations, and if I select the invoices, it will ony show lists of invoices.

Sorry this is a bit of a long question, but I hope all the information is there for someone to assist.

Many thanks, Tom

PostPosted: Wed Jul 15, 2009 8:04 pm
by shannah
Hi Tom,

To achieve what you want, you'll need to use a little javascript and ajax. You can add an onchange handler to your select list using widget:atts:onchange. This javascript function would then repopulate the other select lists according to what you need.

I think there have been a couple of similar questions on the forum over the years. If you browse through you should be able to find some of those discussions.

-Steve