I'm pretty rookie at this, so, apologies. I've flattened my styling, so it's easier to paste in here, but the principles should still work.
I've got a list of items, a search field (which works) and filter buttons (which work). What I need is for the filter buttons to reset to 'All' is active, when the search field is clicked, as the search field searches all items.
Could anyone advise...? I've tried all sorts of different methods but can't get the damn thing going.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="http://code.jquery.com/jquery-2.0.0b1.js"></script>
<!-- SEARCH LIST SCRIPT-->
<script>
function searchTable() {
// Declare variables
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById('imtListInput');
filter = input.value.toUpperCase();
ul = document.getElementById("imtList");
li = ul.getElementsByTagName('li');
// Loop through all list items, and hide those who don't match the search query
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
</script>
<!-- TABLE SHOW HIDE SCRIPT-->
<script>
function show(champ) {
$('ul li').hide()
$('ul li:has(a.' + champ + ')').show()
}
</script>
<!-- SEARCH CLICK SCRIPT-->
<script>
function searchClick() {
$('ul li').show()
//RESET SELECTED BUTTON TO 'ALL'
}
</script>
</head>
<body>
<div style="padding-bottom:10px;" class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-primary btn-lg active">
<input type="radio" name="options" id="option1" autocomplete="off" checked onclick="$('ul li').show()"> All
</label>
<label class="btn btn-primary btn-lg">
<input type="radio" name="options" id="option2" autocomplete="off" onclick="show("Section1")"> Section1
</label>
<label class="btn btn-primary btn-lg">
<input type="radio" name="options" id="option3" autocomplete="off" onclick="show("Section2")"> Section2
</label>
</div>
<input type="text" id="imtListInput" onkeyup="searchTable()" onclick="searchClick()" placeholder="Search...">
<ul id="imtList">
<li><a class="Section1" href="#">File 1</a></li>
<li><a class="Section1" href="#">File 2</a></li>
<li><a class="Section1" href="#">File 3</a></li>
<li><a class="Section1" href="#">File 4</a></li>
<li><a class="Section1" href="#">File 5</a></li>
<li><a class="Section2" href="#">File 6</a></li>
<li><a class="Section2" href="#">File 7</a></li>
</ul>
</body>
</html>