• I have very nearly achieved what I want to do with wp_dropdown_pages().. namely have a drop down menu of certain child pages, with the user able to navigate to each page by selecting them (ie, no submit button).

    However, the problem I have is that the first page in the list is not active as a link.. and it is always displayed as the first item in the list, no matter which page the user is on.

    Here’s my code (taken from online examples, I am new to JS)

    <div class="menu">
    <?php wp_dropdown_pages($args = array('child_of'=>38)); ?>
    <script type='text/javascript'>
    /* <![CDATA[ */
      var dropdown = document.getElementById("page_id");
      function onPageChange() {
        if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
          location.href = "<?php echo home_url(); ?>/?page_id="+dropdown.options[dropdown.selectedIndex].value;
        }
      }
      dropdown.onchange = onPageChange;
    
    </script>
    </div>

    I would like to either

    A) Have all the page links work and the list display the current page that the user is on (preferred)

    or B) Have the default display something like “Select Page”, and have all the drop down page links work.

  • The topic ‘Problem with wp_dropdown_pages() (without Submit Button)’ is closed to new replies.