This is how far I’ve got so far Roland
What I need to know is how do I fill the array for the variable $tidal_location which is in a dropdown menu and how would I format it?
[insert_php]
$current_user = wp_get_current_user();
$wp_username = $current_user->user_login;
$user_id = Participants_Db::get_record_id_by_term(‘username’,$wp_username);
$data = Participants_Db::get_participant($user_id);
$tidal_area = $data[‘tidal_area’];
$tidal_location = $data[‘tidal_location’];
switch ($tidal_area) {
case “UK Channel Islands”:
// load array for Channel Islands
break;
case “UK England”:
// load array for England
break;
case “UK Ireland”:
// load array for Ireland
break;
default:
echo ‘No Tidal Area Specified…’;
}
[/insert_php]
Something like this has to be done in Javascript, you can’t do it in php.
Check out this article, I think I sent you there before, it explains one way to do this: Dropdown Selectors: limit selections based on another selector
Okay Roland I followed your instructions
I wanted to use the ‘pdb-record-default’ template so I copied it and named it ‘pdb-record-arcona’. I then copied the javascript code into the template file. The script went straight after the top closing ?> tag. In this new template file I changed the name of the parent to ‘tidal_area’ and the child to ‘tidal_location’. These are the names of my fields in PDB. I then uploaded my new template file to my templates folder.
In Manage DataBase Files I have the two fields described above. I copied your sample State text into my tidal_area dropdown list. I then copied the sample city text into my tidal_location dropdown list.
All was going well
I inserted the following shortcode into one of my pages. The shortcode contains tidal_area and tidal_location.
[pdb_record template=”arcona” fields=”username,boat_name,boat_model,sail_number,boat_owner,build_year,boat_length,berthed_at,tidal_area,tidal_location,tidal_days,state,city,latitude,longitude,registration,registration_no,radio_callsign,mmsi,website_address,brief_description,single_photo” record_id=1008]
The parent dropdown field (tidal_area) contained the states as expected. I selected one of the states and when I went to the child dropdown field (tidal_location) it contained all the states and all the cities. It hadn’t restricted the list and basically its not working.
Is there anything obvious I’ve missed out. If not is it possible that the template needs updating.
Many thanks
I’m sorry…nothing I see there indicates what the problem is, but most likely you’ll need to debug your javascript. Your browser developer tools are very helpful for that.
I’ve found the problem Roland – Browsers!!!
It works with Firefox, Chrome on my iMac.
It doesn’t work on Safari on my iMac.
I’ve tried differents templates and the result is the same.
I’ve tried Firefox, Chrome, Safari on my iPad and it doesn’t work with any of those.
Any suggestions
Thanks
Make sure your javascript is compatible with all browsers. You can use the Browser Developer tools console to look for issues with the javascript when testing the page.
The javascript I’m using Roland is the one from the link you provided.
i.e. Dropdown Selectors: limit selections based on another selector.
Do you know of any problems with at script?
Thanks
I’ve abandoned that. It’s too unreliable…