Filtered Drop Down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kerepuki
Forum Commoner
Posts: 30
Joined: Fri Oct 29, 2004 12:28 am

Filtered Drop Down

Post by kerepuki »

Hi all,

I will try to explain this the best I can.

OK,

1. I have a drop down menu which is getting its values from a table in my DB. (Business) Working great!
2. I have a text field on the same page with a plus (add) button. (Contact) Easy
3. When I click this plus (add) button, I want to open a new page which will list contacts however I want to filter the contacts to only show the available people for the select business from the drop down.
4. Then inside this popup window have a select button which will close the window and insert the selected contacts name into the contact text field.

So for example:
Business One - Person One, Person Two;
Business Two - Person One, Person Three, Person Four;

If Business One is selected in the drop down then the contact list will only show Person One and Person Two.

Step 3 and 4 is what I am struggling on. Any ideas?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Filtered Drop Down

Post by Christopher »

You can implement the "popup" as a new window created when the form submitted by setting the target="" property of the form. Or you can use Javascrpt to open a window, but you will need to look through the DOM to find the value of the selection to pass.

Look into the Javascript 'opener' object to set the value in the form from a child window.
(#10850)
kerepuki
Forum Commoner
Posts: 30
Joined: Fri Oct 29, 2004 12:28 am

Re: Filtered Drop Down

Post by kerepuki »

Hey, thanks for your reply, I worked it out.

For anyone who is interested:

I am getting the value through javascripts getElementId. My select tag has an onChange event which runs the javascript function. Then my plus (add) button opens a popup window passing window.open("my_page.php?business_id="+document.forms.my_form.business_id.value. This way I can use $_GET to grab the value and use it to filter my records.

Then on the popup I am passing parameter to a function to set the selected contact and using window.opener.my_form.contact.value = contact_name; to pass the value back to the form.

Hope this helps someone.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Filtered Drop Down

Post by Christopher »

Thanks for posting your solution. :) If you have some time, perhaps you should post a a small working example. If if you are feeling adventurous, create a generic solution and post it in Code Critique.
(#10850)
kerepuki
Forum Commoner
Posts: 30
Joined: Fri Oct 29, 2004 12:28 am

Re: Filtered Drop Down

Post by kerepuki »

When I finish the preject I will create a stripped down version and post it.
Post Reply