Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JavaScript is 100% incompatible with the django template. The django template renders HTML and Javascript, then the javascript runs - at that point, template tags do not even exist.</p> <p>You'll have to store option value -> URL combinations with django in a javascript array.</p> <pre><code>### Javascript map urlMap = { {% for value in build_history.values %} {{ value.build_id }}: '{% url build_details value.build_id %}' {% if not forloop.last %},{% endfor %} {% endfor %} }; function onSelectChange(){ var select = $("#action_menu option:selected"); if(!(select.val() == "")) var build_id = select.val().replace('build_',''); window.location.href=urlMap[build_id]; } </code></pre> <p>You could use jQuery's <code>data</code> function to bind data to an element too: </p> <pre><code>### Jquery data {% for value in build_history.values %} $("#action_menu option[value=build_{{ value.build_id }}]") .data('href', '{% url build_details value.build_id %}'); {% endfor %} function onSelectChange(){ var select = $("#action_menu option:selected"); if(!(select.val() == "")) window.location.href=select.data('href'); } </code></pre> <hr> <p>Please copy and pasting this.</p> <pre><code>&lt;script type="text/javascript"&gt; urlMap = { {% for index, value in build_history.items %} '{{ value.build_id }}' : '{% url build_details value.build_id %}'{% if not forloop.last %},{% endif %} {% endfor %} }; $(function() { $("#foo").change(function() { window.location.href = urlMap[$(this).val()]; }); }) &lt;/script&gt; &lt;select id="foo"&gt; &lt;option value=""&gt;---&lt;/option&gt; {% for index, value in build_history.items %} &lt;option value="{{ value.build_id }}"&gt;Build Details&lt;/option&gt; {% endfor %} &lt;/select&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload