Creating a jump menu with auto nav block
Permalink 1 user found helpful
Hi there, I'm not sure if this has been done already, but I'm trying to modify an auto nav template to display the navigation as a jump menu (working with javascript). Here is my template code (jump_menu.php):
and here is my javascript....
I can get the form field to show up, but the option fields do not populate from the sitemap. Any suggestions?
<?php defined('C5_EXECUTE') or die("Access Denied."); $aBlocks = $controller->generateNav(); $c = Page::getCurrentPage(); echo("<div class='site_quick_jump_container'>"); echo("<form id='find_branch_footer' class='site_quick_jump_form' method='get' action=''>"); echo("<label for='find_branch_footer'></label>"); echo("<select name='fb_list' id='fb_list' class='site_quick_jump' title=''>"); echo("<option value=''>Find your branch</option>"); $nh = Loader::helper('navigation'); $isFirst = true; foreach($aBlocks as $ni) { $_c = $ni->getCollectionObject(); if (!$_c->getCollectionAttributeValue('exclude_nav')) { $target = $ni->getTarget();
Viewing 15 lines of 47 lines. View entire code block.
and here is my javascript....
<script type="text/javascript" charset="utf-8"> //<![CDATA[ $(document).ready(function() { $('.site_quick_jump').change(function(){ // option 1 use a JS redirect in the current window //window.location.href = $(this).val(); // option 2; set the 'action' of the form and submit it if ($(this).val() != '') { $('.site_quick_jump_form').attr('action', $(this).val()); // $('.site_quick_jump_form').attr('target', '_self'); // new window $('.site_quick_jump_form').submit(); // Go! } }); }); // doc ready //]]>
Viewing 15 lines of 16 lines. View entire code block.
I can get the form field to show up, but the option fields do not populate from the sitemap. Any suggestions?
OK, I think I see something that may be causing problems. The loop is actually adding in extra (nested) option tags. Here is the original snippet from your code:
Here is a suggested change (replace the snippet above with just the code below):
if ($isFirst) $isFirstClass = 'first'; else $isFirstClass = ''; echo '<option class="'.$navSelected.' '.$isFirstClass.' selected="selected">'; if ($c->getCollectionID() == $_c->getCollectionID()) { echo('<option selected="selected" value="' . $pageLink . '" ' . $target . '>' . $ni->getName() . '</option>'); } else { echo('<option value="' . $pageLink . '" ' . $target . '>' . $ni->getName() . '</option>'); } echo('</option>'); $isFirst = false;
Here is a suggested change (replace the snippet above with just the code below):
Thanks!!!!
I was searching the forums to see if some one attempted to create a select nav template and stumbled upon this thread. I wish to thank @jkernick and @jeramy.
Do the pages that you want to populate into the option values have the custom attribute 'exclude_nav' set as false (unchecked)?