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):

<?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();


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
//]]>


I can get the form field to show up, but the option fields do not populate from the sitemap. Any suggestions?

jkernick
 
jeramy replied on at Permalink Reply
jeramy
This worked on my test install from your code.

Do the pages that you want to populate into the option values have the custom attribute 'exclude_nav' set as false (unchecked)?
jeramy replied on at Permalink Best Answer Reply
jeramy
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:

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):

if ($c->getCollectionID() == $_c->getCollectionID()) { 
            echo('<option selected="selected" value="' . $pageLink . '"  >' . $ni->getName() . '</option>');
         } else {
            echo('<option value="' . $pageLink . '"  ' . $target . '>' . $ni->getName() . '</option>');
         }
jkernick replied on at Permalink Reply
jkernick
Thanks!!!!
rudrum replied on at Permalink Reply
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.