Jump to content

Tips on populating a dropdown from another dropdown


cb2004
 Share

Recommended Posts

Can anybody offer up any tips for this? Basically on a contact form there are certain services, and certain staff members are assigned to those services. When a service is selected in a dropdown, I only want the staff members assigned to that service to be displayed in another dropdown. Guessing it is venturing into Ajax which I have not done with ProcessWire yet.

Cheers.

Link to comment
Share on other sites

So in my form I am selecting the services:

foreach ($pages->get(1040)->children as $child) {
	$service .= '<option value="' . $child->id . '">' . $child->title . '</option>';
}

This is then returning a nice set of options to interrogate from ID:

<select name="service" id="service">
	<option value="1041">Service 1</option>
	<option value="1042">Service 2</option>
</select>

So I am thinking next step is to put a PHP file on the server which would do a $pages->find("template=service, page_staff=VALUE") using Ajax and return the results with the staff name?

Link to comment
Share on other sites

Yes I thought that as well. So I am giving each option in the staff dropdown classes:

<option value="Staff member" class="1041 1045 1046 1048">Staff member</option>

Then if the service dropdown selected is value="1041", only those staff members will be selected. Just got to work on the jQuery and then all done.

Link to comment
Share on other sites

Admittedly I don't fully understand your needs, but PW has some inbuilt support for this if you are using Page fields. You can do something like this:

parent=page.service

for the page field's "define selector to find pages". This will create an ajaxified UI for field relations.

It may not work for what you need, but thought I'd mention it just in case.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...