1

I would like to choose entry values from a frontend dropdown and reuse the chosen value directly.

{% set entries = craft.entries.section('mountainbikes') %}

<select name="year">
{% for entry in entries %}
  <option value={{ entry.year }}>{{ entry.year }}</option>
{% endfor %}          

How can i get the chosen value and reuse it in the same template? For example:

{% for entry in entries %}
  {% if entry.year == '2015' %} /* chosen value in dropdown field */
    {{ entry.title }}
  {% endif %}
{% endfor %}

Thanks for any help!

  • Just to clarify, you want to use the chosen value elsewhere in the template on the same request? i.e. without hitting a submit button somewhere and using it on another page. – Brad Bell Feb 24 '17 at 0:44
  • Actually, yes - on the same request. I would like to build a little suspension setup calculator, where i'd like to choose the bike first by year and second by modell (Both are field entries). Then put out the appropriate setup values. – TomS Feb 24 '17 at 7:11
  • 1
    If you want to do that without making a request to the server, you'll need to use JavaScript to retrieve the selected value. – Stephen Lewis Feb 24 '17 at 8:22
1

i've got now a working approach to my question above:

{% set field = craft.fields.getFieldByHandle('jahrgang') %}

<form action="tourdefrance.html" method="post">
   <select class="dropdown" name="modelljahr" size="1" onchange="this.form.submit();">
     {% for opt in field.settings.options %}
        <option name="fields[myFieldHandle][]" value="{{ opt.value }}">{{ opt.value }}</option>
     {% endfor %}
   </select>

{% set entries = craft.entries.section('mountainbikes') %}

{% set modelljahr = craft.request.getParam('modelljahr') %}

<form action="tourdefrance.html" method="post">
  <select class="dropdown" name="modell" size="1" onchange="this.form.submit();">
    {% for entry in entries %}
      {% if entry.jahrgang == modelljahr %}
        <option value="{{ entry.title }}">{{ entry.title }}</option>
      {% endif %}
    {% endfor %}
  </select>

{{ craft.request.getParam('modell') }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.