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.

Making a dropdown selection 'stick'

July 06, 2007 8:19pm

Subscribe [0]
  • #1 / Jul 06, 2007 8:19pm

    APGWest

    295 posts

    I use the following code to filter entries by category:

    <select name="selcat" onchange="location=document.catmenu.selcat.options[document.catmenu.selcat.selectedIndex].value;">
    <option value="">--Select Category--</option>
    <option value="{path="/{my_weblog}}">ALL</option> 
    {exp:weblog:categories weblog="{my_weblog}" style="linear" dynamic="off"}
    <option value="{path={my_weblog}}">{category_name}</option>
    {/exp:weblog:categories}
    </select>

    It works like a champ but it doesn’t continue to show the option that I selected.  Is there a quick and dirty fix for this?

  • #2 / Jul 06, 2007 9:43pm

    Stephen Lewis

    466 posts

    Hi there,

    I’m something of a newbie, but I think you could make this work by checking the URL segment to see if it matches your category ID. Whether or not (or at least how) this would work depends on whether you have decided to use Category URL Titles in your links.

    If not, the code would be something like this:

    {exp:weblog:categories weblog="{my_weblog}" style="linear" dynamic="off"}
    <option value="{path="weblog_name"}" {if segment_2 == category_id}selected="selected"{/if}>{category_name}</option>
    {/exp:weblog:categories}

    If you have got the Category URL Titles enabled, I’m guessing your URL would change from http://example.com/index.php/weblog_name/C12 (for example) to something like http://example.com/index.php/weblog_name/category/category_name/.

    In that case, the code would be something like this:

    {exp:weblog:categories weblog="{my_weblog}" style="linear" dynamic="off"}
    <option value="{path="weblog_name"}" {if segment_3 == category_url_title}selected="selected"{/if}>{category_name}</option>
    {/exp:weblog:categories}

    I haven’t tested any of this, but hopefully it will give you something to go on.

    Cheers
    Stephen

  • #3 / Jul 07, 2007 6:35am

    APGWest

    295 posts

    I’m running the category IDs but unfortunately that didn’t seem to do anything.  It rolled right back to the “Select Category” each time an option is picked and the page loads.

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

ExpressionEngine News!

#eecms, #events, #releases