Python Forum
problem using drop down list to filter table.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem using drop down list to filter table.
#1
Hi am trying to make a filter for my table with a drop down list but i got some problems with that it doesent do anything. The drop down list get its data from sqlite db but if i do not use a db and write the options in the html file it works.

Here is the lines of code for the drop down list.

List.html

<select id="mylist" onchange="myFunction2()" class='form-control'>
{% for data in datas %}
<option value="{{ data.anstallda }}">{{ data.Namn }}</option>
{% endfor %}
</select>

function myFunction2() {
  var input, filter, table, tr, td, i;
  input = document.getElementById("mylist");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[0];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }       
  }
}
From the python file
@app.route('/list')
def list():
   con = sql.connect("database.db")
   con.row_factory = sql.Row
   
   cur = con.cursor()
   cur.execute("select * from tider")
   
   rows = cur.fetchall();

   cur.execute("SELECT * FROM anstallda")
   datas = cur.fetchall();     

   
   return render_template("list.html",rows = rows, datas = datas)
Reply
#2
Is that javascript function in a <script type="text/javascript"> tag? Or is that a direct copy-paste? Because browser won't run javascript that's outside script tags (because how is that different from plain text?)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Flask]filter posts from list SheeppOSU 0 2,262 May-30-2019, 03:48 PM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020