problem using drop down list to filter table. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: problem using drop down list to filter table. (/thread-16997.html) |
problem using drop down list to filter table. - darktitan - Mar-23-2019 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) RE: problem using drop down list to filter table. - nilamo - Mar-27-2019 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?) |