All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Retaining seltected option

Ross Hulford 24 Mar 2014 16:32 question, complete

Hi,

I have 3 elect boxes and would like to add a 'selected' class after it has been selected, is this possible?

Country

Please Select
{exp:low_options:country}
{options}{option:label}{/options}

{/exp:low_options:country}

Replies

  1. Low 24 Mar 2014 17:51

    Do you mean inside Low Search? Then you can use a conditional like this:

    {if option:value == '{low_search_search:country}'} ... {/if}


    Or if it has multiple options:

    {if option:value IN ({low_search_search:country})} ... {/if}

  2. Ross Hulford 25 Mar 2014 09:35

    Hi,

    Trying this but getting an error

    {exp:low_options:country}
    {options}{option:label}
    {/options}

  3. Low 25 Mar 2014 09:38

    What error message is that? Some HTML is stripped out. To avoid, you can use http://pastie.org/ or http://pastebin.com/ for large chunks of code.

  4. Ross Hulford 25 Mar 2014 09:43

    sorry here is the full form

    http://pastie.org/8966743

  5. Low 25 Mar 2014 09:45

    If you're encoding the query in the URI, you will need to add the query="" parameter to the Form tag, so it can remember the search query.

    You're also missing a closing curly bracket. It should be this:

    {if option:value IN ({low_search_search:country})} selected {/if}

  6. Ross Hulford 25 Mar 2014 10:21

    Still getting the error

    Parse error: syntax error, unexpected 'FALSE' (T_STRING)

    It looks ok

    http://pastie.org/8966827

  7. Low 25 Mar 2014 10:26

    Make sure the query="" parameter points to the encoded query in the URI, eg. query="{segment_3}" (or {segment_2}, if that's the case).

    Also, not seeing any conditionals in that last pastie you shared.

  8. Ross Hulford 25 Mar 2014 10:51

    sorry here it is

    http://pastie.org/8966895

    The problem seems to be with {option:value}

  9. Low 25 Mar 2014 10:53

    Can you try this instead?

    {if '{option:value}' IN ({low_search_search:country})} selected {/if}

  10. Ross Hulford 25 Mar 2014 11:19

    So I encoded the url.

    http://pastie.org/8966936

    I have no errors adding the '{option:value}' but it does not retain the value

  11. Low 25 Mar 2014 11:26

    As I said, you need to add query="{segment_3}" to the Form tag if you're encoding the query. Your code currently doesn't have it, so it has no way of knowing what was submitted.