PDA

View Full Version : Combo Box viewer: remembering after reloading



aharvey
08-07-2005, 09:54 PM
Script: Combo Box viewer

http://www.dynamicdrive.com/dynamicindex17/comboviewer.htm

Problem: I'd like to have the combo box list contain links that call the same page that the combo box itself is on, but doing so resets the combo box to the first selection on the list, even in the absence of instructions to do so. Is there any way to have the same selected choice and corresponding subset of links persist?

In case this isn't clear, here's my working document:

http://www.bio.georgiasouthern.edu/GR-inverts/grlistmod1.html

The combo box in question is in the left column. Clicking on the link is supposed to insert stuff relevant to the chosen species in the proper location in the right column. The problem to which I refer can be seen if you select a list other than Annelida (say, Vertebrates), and then click on a species name from the new list. You get the proper information on the right, but the combo box on the left resets itself to Annelida. I'd rather the combo box in this example continue to show the Vertebrates list rather than revert to the Annelid list!

(By the way, I know there are other things that don't work on this page yet. I'm plowing through the issues one at a time. You should have seen this thing this morning!)

Thanks in advance for any suggestions.

Alan

jscheuer1
08-08-2005, 06:20 PM
resets the combo box to the first selection on the list, even in the absence of instructions to do soWell, reloading the page is 'instructions to do so'. When you click on one of those links you are reloading the page with new information in the address as to what to display on the right. So anyways, to avoid this we must give additional instructions on page load. I see you are already passing information to the page about what to display on the right. If you test the url you could determine which drop contents to display based upon that:

<script type="text/javascript">
var chkURL=unescape(location.href)
if (chkURL.indexOf('Actinopygaagassizii')!==-1)
document.dropmsgform.dropmsgoption.selectedIndex=5
</script>This script should go directly after the the form. Remember that options are numbered starting at 0 so 5 corresponds to:

<option>Echinodermata (sea stars, sea cucumbers, sea urchins, etc.)</option>You will of course need to expand considerably upon the above script adding in tests for each ?spp= keyword that you have and associating it with the correct option number from the form. Just follow the the pattern of:

if (chkURL.indexOf('wordToCheckFor')!==-1)
document.dropmsgform.dropmsgoption.selectedIndex=actualNumberOfOptionadding each beneath the one I've supplied:

<script type="text/javascript">
var chkURL=unescape(location.href)
if (chkURL.indexOf('Actinopygaagassizii')!==-1)
document.dropmsgform.dropmsgoption.selectedIndex=5
if (chkURL.indexOf('wordToCheckFor')!==-1)
document.dropmsgform.dropmsgoption.selectedIndex=actualNumberOfOption
</script>Order is unimportant but, you will want to go in sequence to make sure you haven't missed any.

aharvey
08-08-2005, 07:18 PM
John,

Thanks for your insights. That specific approach would have been impractical since there are already over 300 species on the list and counting, but I was able to modify your suggestion to get the desired result by adding info to the URL and including a stripped-down version of the script you provided. Works like a charm.

Can't tell you how much this site has helped me!