ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Populate Dropdown with Channel Entries?

October 15, 2010 5:47pm

Subscribe [2]
  • #1 / Oct 15, 2010 5:47pm

    Josh B.

    22 posts

    I’m trying to implement a “Quick Search” feature.  This feature would display a dropdown menu form to the user, and the user could select a Channel entry url_title from this list.  Is there anyway that I can automatically populate this dropdown with the contents of a channel?

    Thanks,

    Josh

    Moved to CodeShare Corner by Moderator

  • #2 / Oct 15, 2010 6:02pm

    Rob Allen

    3114 posts

    Sure, something like this?

    <form name="dropmenu" action="">
    <select name="entry">
    <option value="">-- Select an entry --</option>
      {exp:channel:entries channel="channel_name" limit="10"}
      <option value="{url_title_path='template_group/template'}">{title}</option>
      {/exp:channel:entries}
    </select> 
    <input type="submit" value="Go" />
    </form>

    This is really a slightly modified version of the categories drop down found in the docs -http://ellislab.com/expressionengine/user-guide/modules/channel/categories.html

  • #3 / Oct 17, 2010 5:35pm

    Josh B.

    22 posts

    Thanks!  Almost have it.  My code looks like:

    <form class="choosecounty" action="#">
                    <div>
                    <label>Choose a county below:</label>
                    <select name="county">
                        {exp:channel:entries channel="counties" sort="asc"}
                        <option value="{url_title_path='county'}">{title}</option>
                        {/exp:channel:entries}
                    </select>
                    <input type="submit" value="Go" />
                    </div>

    When a user selects a county and hits the submit button, they are redirected to:

    http://dev.blah.com/?county=http://dev.blah.com/index.php/county/fulton#

    They should go to http://dev.blah.com/county/fulton.

    Any idea how to fix that?

    Thanks!

  • #4 / Oct 17, 2010 5:59pm

    Rob Allen

    3114 posts

    Ah, checkout out the code snippet at http://ellislab.com/expressionengine/user-guide/modules/channel/categories.html  (near bottom of page) - you’ll probably have to add in the bit of javascript, an obviously modify the code to use exp:channel:entries instead of exp:channel:categories in the SELECT tag

  • #5 / Oct 17, 2010 6:59pm

    Genevieve

    52 posts

    I’m trying to do something similar to Josh B., and I’m trying to use the category menu drop-down menu, but I have no idea how to go about editing the javascript to make this go. Can anyone help break down the javascript the category menu uses, so I can reconstruct it for an entries drop-down menu?

  • #6 / Oct 17, 2010 8:21pm

    Rob Allen

    3114 posts

    You don’t need to change the javascript, just the EE exp:channel:categories to use exp:channel:entries to control the pages you want listed. I can’t post the complete code because the forum strips out the javascript but this might give you an idea…

    <form name="catmenu" action="">
    <select name="selcat" [insert the "on change" attribute here]>
    <option value="">--Select entry--</option>
    {exp:channel:entries channel="yourchannel"}
    <option value="{url_title_path='template_group/template'}">{title}</option>
    {/exp:channel:entries}
    </select>
    </form>
  • #7 / Oct 17, 2010 10:13pm

    Josh B.

    22 posts

    Ok.. still not getting the right results for some reason:

    <form class="choosecounty" action="#">
                    <div>
                    <label>Choose a county below:</label>
                    <select name="county">
                        {exp:channel:entries channel="counties" sort="asc"}
                        <option value="{url_title_path='county'}">{title}</option>
                        {/exp:channel:entries}
                    </select>
                    <input type="submit" value="Go" />
                    </div>
                </form>

    The forum probably cuts the JS out, but I copied the onchange from the doc page, and swapped “catmenu” for “choosecounty” (the name of my form), and “selcat” for “county” (the name of my select).  Same results..

    http://dev.blah.com/?county=http://dev.blah.com/index.php/county/fulton#

    ..instead of:

    http://dev.blah.com/county/fulton

    Any ideas?

    Thanks

  • #8 / Oct 17, 2010 10:19pm

    Rob Allen

    3114 posts

    Try it without changing the javascript and using action=”” without the hash

  • #9 / Oct 17, 2010 10:22pm

    Josh B.

    22 posts

    Hrm, same results.

  • #10 / Oct 17, 2010 10:34pm

    Rob Allen

    3114 posts

  • #11 / Oct 18, 2010 11:50am

    Josh B.

    22 posts

    Hrm, it looks like EE is modifying something.  No matter what method I use, the “value” (the URL) of the <option> always gets appended as a variable when redirected..

    <option value="http://google.com">{title}</option>

    http://dev.blah.com.com/?county=http://google.com

  • #12 / Oct 18, 2010 12:10pm

    Josh B.

    22 posts

    Ok.. finally got it working.  It does however append index.php, which I am working on removing.  Here is the code that I used:

    [removed]
                    function changeLocation(menuObj) {
                      var i = menuObj.selectedIndex;
                      if(i > 0) {
                        [removed] = menuObj.options[i].value;
                      }
                    }
                [removed]
    
                <form class="choosecounty" action="">
                    <div>
                    <label>Choose a county below:</label>
                    <select id="gowhere" name="county">
                        {exp:channel:entries channel="counties" sort="asc"}
                        <option value="{path='county/{url_title}'}">{title}</option>
                        {/exp:channel:entries}
                    </select>
                    <input type="submit" value="Go" />
                    </div>
                </form>
  • #13 / Oct 18, 2010 12:13pm

    Josh B.

    22 posts

    bluedreamer,

    One problem is that when I use the “quicksearch” dropdown to browse to a entry in a channel, once on that page, the dropdown only contains one item - the url_title of the page that is currently being shown.  I thought that was odd, considering the code is the same no matter what page you are on—it is simply embedded in the template.  Any idea what may be causing this?

    Thanks,

    Josh

  • #14 / Oct 18, 2010 12:39pm

    Josh B.

    22 posts

    dynamic=“off” fixed my problem.  Thanks for the help!

  • #15 / Oct 18, 2010 1:40pm

    Rob Allen

    3114 posts

    Well done, glad you cracked it!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases