I have the following codes. checkbox for compare value in table row
Problem:
1 ) when table value same multiple row it will hide all I want to complare 1 checkbox 1 row
2 ) why funtion will start work when checked box ? I want to start function onload window
Fiddle: http://jsfiddle.net/4sx1pdmn/
Can anyone advise with my codes?
function filterCondtn1(event) {
var element = event.target
var condt1 = document.getElementsByClassName("option")
for (var i = 0; i < condt1.length; i++) {
if (condt1[i].innerHTML.toLowerCase() == element.value.toLowerCase()) {
if (element.checked == true) {
condt1[i].parentElement.style = "display:none"
} else {
condt1[i].parentElement.style = "display:block"
}
}
}
}
table {
border-collapse : collapse;
margin : 2em 1em;
}
td,th {
padding : .2em .8em;
border : 1px solid darkblue;
}
<div id="InputOpts">
<input type="checkbox" value="1" oninput="filterCondtn1(event);">Option 1
<input type="checkbox" value="1" oninput="filterCondtn1(event);">Option 2
<input type="checkbox" value="2" oninput="filterCondtn1(event);">Option 3
</div>
<table id="myTable">
<tr>
<th>Name</th>
<th>Country</th>
</tr>
<tr>
<td class="option">1</td>
<td>1</td>
</tr>
<tr>
<td class="option">2</td>
<td>2</td>
</tr>
<tr>
<td class="option">3</td>
<td>3</td>
</tr>
<tr>
<td class="option">1</td>
<td>1</td>
</tr>
</table>
Sorry for my bad English, can't explain all what I need, hope you understand what I need
style.display = "block"on a<tr>element will BREAK your table. Either set it to""to return it to default, or explicity set it to"table-row", its actual default.