I have a sorted list of objects that I want my users to select a range from. For this I added two select elements (called from and to)to my web page. from is filled directly from the list, like this:
<select id="from">
{% for el in el_list %}<option>{{el.number}}</option>{% endfor %}
</select>
Once a value has been selected in from I’d like to populate to with the values from the selected value until the last one.
The list is sorted by the number attribute on python’s side so I guess all I need to do is find the selected element in the list, slice the list accordingly and use the rest to populate my second select.
I’ve searched the documentation and several snippets but so far I’ve only found filters giving me the last or the first element of a list. I also know I can check if the selected value is in my list using in, but how can I then get that object’s index?
I know I could probably run along the whole list with a for … if, but I am almost sure there’s a more elegant method out there, that I simply haven’t found yet.
If any of you could provide me with a few pointers on how to solve this more elegantly it’d be much appreciated.
I don’t know why you’re looking through template tags for this. They won’t help: by the time the user sees the page to select something from the
fromselect, the template has already been rendered. You need to use Javascript.