diedVIPs

html knowhow

Suche in einer Tabelle










Suche in einer Tabelle

Geben Sie einen Namen in das rote Feld ein und suchen Sie einen Namen in der Tabelle
So sieht´s aus
Name Beruf
Hans Busch Verleger
Mike Brown Actor
Natalie Decamps Autor
Petro Gonzales Maurer
Henry Miller Buchhalter
Jo Frazer Boxer
Karin Lieberwirth Hausfrau
Ole Bjönsen Fischer

Quellcode
<html>
<head>
<style type="text/css">
* {box-sizing: border-box;}
#myInput {background-color:transparent; background-position: 10px 10px; background-repeat: no-repeat; width: 50%; font-size: 16px;
padding: 12px 20px 12px 40px; border: 1px solid red; margin-bottom: 12px;float:left}
#myTable {border-collapse: collapse; width: 100%; border: 1px solid #ddd; font-size: 18px;}
#myTable th, #myTable td {text-align: left; padding: 5px;}
#myTable tr {border-bottom: 1px solid #ddd;}
#myTable tr.header, #myTable tr:hover {background-color: #f1f1f1;}
</style>
</head>

<body>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Suche nach einem Namen .." title="Type in a name"/>
<table id="myTable">
<tr class="header">
<th style="width:60%;">Name</th>
<th style="width:40%;">Beruf</th>
</tr>
<tr>
<td>Hans Busch</td>
<td>Verleger</td>
</tr>
<tr>
<td>Mike Brown</td>
<td>Actor</td>
</tr>
<tr>
<td>Natalie Decamps</td>
<td>Autor</td>
</tr>
<tr>
<td>Petro Gonzales</td>
<td>Maurer</td>
</tr>
<tr>
<td>Henry Miller</td>
<td>Buchhalter</td>
</tr>
<tr>
<td>Jo Frazer</td>
<td>Boxer</td>
</tr>
<tr>
<td>Karin Lieberwirth</td>
<td>Hausfrau</td>
</tr>
<tr>
<td>Ole Bjönsen</td>
<td>Fischer</td>
</tr>
</table>

<script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
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) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
</body>

</html>







Kontakt    Datenschutz    Impressum