close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Retaining Dynamic Dropdowns Search options on page reload

Thread began 3/05/2011 7:56 am by paul386190 | Last modified 3/10/2011 12:25 pm by Jason Byrnes | 2029 views | 5 replies |

paul386190

Retaining Dynamic Dropdowns Search options on page reload

Hi there

I have managed to set up a search facility using a couple of linked dynamic dropdowns and the data assist search wizard within a client's admin tool. Basically they make a selection from the first dropdown - this dynamically populates the second dropdown, they then make a selection from the second dropdown and hit a 'search' button. I've set up the page to be both the search and results page so when page then refreshes is displays the search facility and the results. However, the problem I'm having is getting the two dropdowns to retain their original search selections on the page reload. For example, if they select 'Car' from the first and 'Ford' from the second, when they hit the search it reloads the page with the results but the dropdowns are still displaying 'Car' and 'Ford'. I was originally able to do this when the search facility only had one dropdown as i could set a 'select value equal to' to the correct id, but it doesn't seem to work now that I'm running two linked dropdowns and the second when doesn't contain any content when initially loaded.

Just to give a little background I have three tables labelled 'Level 1', 'Level 2' and 'Level 3' and their basic structure is...
level1 contains: level1_id and level1_name (this table populates the first dropdown)
level2 contains: level2_id, level2_name and level1_id (this table populates the second dropdown)
level3 contains: level3_id, level3_name and level2_id (this table populates the search results)

I've tried a few variations...

1. No initially selected options (not even a 'Select an option') and Populate List from Array - Target list options - Leave Top set to 0. This just returns with the first value displaying in the first dropdown and the second dropdown empty.

2. The same as above but Leave Top set to 1. This just populates the second menu with an initial empty option when the first dropdown option has been chosen.

3. Setting the initially selected value of the first dropdown to <?php $row_level2['level1_id'] ?>. This dropdown is set with 'Options from Recordset - level1', 'Values - level1_id' and 'Labels - level1_name'. This just gives the same result as the first variation.

4. Same as above but additionally adding <option value=""<?php if (!(strcmp($row_level2['level2_id'], $row_level3['level2_id']))) {echo "selected=\"selected\"";} ?>></option> between the <select></select> tags of the second dropdown. This just gives the same result as the first variation.

I'm guessing it's a fairly straightforward issue that I'm missing and would be extremely grateful for any assistance.
Many thanks in advance.
Paul.

Sign in to reply to this post

Dave BuchholzBeta Tester

I had a similar problem which Jason provided the answer to in this thread showthread.php?t=18111

Sign in to reply to this post

paul386190

Hi Dave

Thank you so much for that, that's worked a treat. I've now added the following three to the body onload in this order...

Selected in list parent (dropdown1) to <?php echo((isset($_GET["parent"]))?$_GET["parent"]:"") ?>

Populated List from Array - Source: level2 - Source List: parent - Target List: child

Selected in list child (dropdown2) to <?php echo((isset($_GET["child"]))?$_GET["child"]:"") ?>


This has now sparked off a couple of other similar issues...

The list of search results which appears simply displays the level3 names and beside each name is a link to an 'update record' page where the client can change the details of this record and then return to the original page which has the search and search results. When I make an update and return to the page, it still displays the correct search results but it hasn't retained the chosen options in either of the dropdowns. Would it require me to pass some kind server variable through to the 'update record' page and then back through to the search results page?

Secondly, the list of search results can be reordered - I've implemented the Table Drag and Drop JQuery plugin to achieve this - so the client can drag one of the results in the list up or down within the list and then clicks an 'Update Order' button. This runs a php page and reloads the search/search results page. I've tried applying the same three behaviours to the onClick of this button, but the 2 dropdowns have lost their selected options when the page reloads.


Any advice you can offer would be greatly appreciated and thank you again for your initial resolution.
Kind regards
Paul

Sign in to reply to this post

Jason ByrnesWebAssist

add the following code at line 1 of your page, this will save the parent and child query string variables to a session and reset the querystrings to use the session value if the querystring is missing:

php:
<?php
if(!session_id()) session_start();
if(isset(
$_GET['parent'])) $_SESSION['parent'] = $_GET['parent'];
if(isset(
$_GET['child'])) $_SESSION['child'] = $_GET['child'];
if(!isset(
$_GET['parent']) && isset($_SESSION['parent'])) $_GET['parent'] = $_SESSION['parent'];
if(!isset(
$_GET['child'])&& isset($_SESSION['child'])) $_GET['child'] = $_SESSION['child'];
?>
Sign in to reply to this post

paul386190

Hi Jason

That's perfect. Thank you very much for the snippet, really appreciate it.

Kind regards
Paul

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...