Answer the question
In order to leave comments, you need to log in
How to pass value from drop down list to view in template?
In the template, so far I have built such a design
<form action="{% url 'cv' format_='???????' %}" method="post">
<fieldset>
<select class="form-control custom-select-main mx-auto" >
<option value="json">json</option>
<option value="html">html</option>
<option value="docx">docx</option>
</select>
</fieldset>
</form>
<a class="btn btn-success" href="{% url 'cv' format=???????? %}">Get CV</a
Answer the question
In order to leave comments, you need to log in
Great way without creating forms
<div id="selector">
<select>
<option value="#">Download</option>
<option value="{% url 'cv' format_='docx' %}">DOCX</option>
<option value="{% url 'cv' format_='json' %}">JSON</option>
<option value="{% url 'cv' format_='html' %}">HTML</option>
</select>
</div>
<script>
$(function(){
// bind change event to select
$('#selector select').bind('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
Assign an action to the form with the required url, add name="format" to the select and put the button into the form. No js is needed here.
Learn to work with forms, and not write crutches, which you will understand later.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question