At first please see the image Result that I want There result will look like this.
There are two select dropdowns, Series and episodes. Initially, the episode filed is empty. When a series is selected, the episode will fetch the data depending on the series. And there are series and episode data on the table. At first, all data will visible. When someone selects a series or episode, table data will be filtered depending on the selected field. I have tried some code, please have a look
<select class="selectpicker" data-live-search="true" id="seriesID">
<option>Select Series</option>
{% for series in series_context %}
<option value="{{series.id}}">{{ series.lesson_title }}</option>
{% endfor %}
</select>
<select id="episodeID">
<option>Select Series</option>
{% for ep_context in episode_context %}
<option value="{{ep_context.series_of.id}}">{{ ep_context.title }}</option>
{% endfor %}
</select>
Table:
<div class="table-responsive" data-toggle="lists" data-lists-sort-by="js-lists-values-orders-name"
data-lists-values='["js-lists-values-orders-name", "js-lists-values-orders-date", "js-lists-values-orders-amount"]'>
<table class="table mb-0 table-nowrap thead-border-top-0">
<thead>
<tr>
<th>SL </th>
<th> Episode </th>
<th> Price </th>
</tr>
</thead>
<tbody class="list" id="episodeTable">
{% for l_context in series_context %}
{% for ep_context in episode_context %}
{% if l_context == ep_context.series_of %}
<tr>
<td>
<p>{{ forloop.counter }}</p>
</td>
<td>
<div class="d-flex align-items-center">
<a class="js-lists-values-orders-name" onclick="changeVideo('{{ep_context.video}}')" href="#" id=" video-link-{{ ep_context.id}}">
<b>{{ ep_context.title }}</b>
</a>
</div>
</td>
<td>
<p><b>${{ ep_context.price }}</b></p>
</td>
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</table>
</div>
Script:
<script>
$(document).ready(function () {
var $seriesVar = $('#seriesID');
var $episodeVar = $('#episodeID');
var $episodeTable = $('#episodeTable');
var $options2 = $episodeTable.find('');
$seriesVar.on('change',function () {
$episodeTable.html($options2.filter('[value="'+this.value+'"]'));
}).trigger('change');
});
</script>
In the backend I use Django. Please help me to find my mistakes or re-arrange my code with the correct formate. How can I find the correct result?