I think the best way to ask for what I am trying to do is:
I have a field on a custom form (add a contact) that has a field called "Company". "Company is a Select (dropdown) list of a separate table called "companies".

Table "companies" has fields for:
company_name
company_phone_primary"
company_address_street (4 lines)
company_address_city
company_address_state
company_address_zip
company_address_country

So, table "companies" has one record for each company, and fields for info about that company.
Now, companies have lots of employees (contacts).

Table "contacts" has fields for:
contact_name_first
contact_name_last
contact_company (a Select dropdown)
contact_phone
contact_address_street
contact_address_city
etc...
contact_company_street
contact_company_city
contact_company_zip
etc

So, assume a whole bunch of companies are already entered into the table "companies". All those fields filled out.
Now, while filling out a "Contact" I want to do this with that Contact's "Company".
1) Select from the "contact_company" select dropdown and look for the company if it already exists.
2) If it DOES exist and is chosen from the select dropdown, then I want the contact_company_street, city, state, country, and zip field to auto-populate from the selected company table record of the same name. (auto-populate those contact fields from that company's company_address fields).

Is this possible?
I've been researching this here on drupal.org for days and I'm only getting mixed incomplete ideas. I see the table_companies table to be a one-to-many relationship, and the contact as a one-to-one relationship (with a company)

Any suggestions on how I should re-approach solution to my dilemma?
hanks in advance for any search phrases or links o articles/modules, anything.
iansears

Notes: I am using CCK, Views, can use Contemplate, etc... Drupal v5.10

Comments

iansears’s picture

How can I populate a select dropdown from another table in the mysql db? (a field in that table)?

and, then when a selection is made,

Is it possible to auto-populate fields in my form from fields in that other db table record?

Please help, this is a time-sensitive task on my plate.

Frustrated.

keva’s picture

will viewfield do this?

I'm really new to views, so that may not be the solution ...

drupalized-1’s picture

I fixed it with a 2-pass form but that isn't so nice.
Can be done with Ajax en JQuery but I don't find a sample of that.

iansears’s picture

drupalized,

Clearly it would be a JavaScript onChange event handler attached to the field, so I can see how valuable your JQuery and Ajax suggestion is, that may narrow down where I am looking significantly. Thank you.

A "two-pass" approach solved this for you? Could you explain a bit what you mean?

Thanks,
Ian

drupalized-1’s picture

It works for me. The "next" button in the first-pass does something like the Javascript onChange event handler and the fills the listbox from the database, depending on the user input of the first form. So actually on the first form the user can select from a listbox that is filled from a given list (not from database), he click's the "next" button and the formstate comes in his second stage which takes the user input from step1 as a condition for filling the second listbox and can the click "submit" in the form.

ycimlynn’s picture

I have also been trying to accomplish this.

I would be interested in knowing exactly how you approached this problem.

Indeed it is a source of frustration for me, also!

Thank you!

iansears’s picture

Thank you for your reply. I looked over viewfield but see nothing mentioned that accomplishes our goal here, but I continue to pursue this. Thank you though, for your generous answer here.
Ian

burningdog’s picture

I found this http://drupal.org/project/hierarchical_select and it autopopulates a select list with child terms based on the first select taxonomy term.