Page 1 of 1

Filtered Drop Down

Posted: Fri Mar 21, 2008 6:03 am
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?

Re: Filtered Drop Down

Posted: Fri Mar 21, 2008 10:41 am
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.

Re: Filtered Drop Down

Posted: Fri Mar 21, 2008 6:18 pm
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.

Re: Filtered Drop Down

Posted: Fri Mar 21, 2008 7:25 pm
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.

Re: Filtered Drop Down

Posted: Sat Mar 22, 2008 9:22 pm
by kerepuki
When I finish the preject I will create a stripped down version and post it.