Just set the onchange
event to your select
, then empty the input text and trigger keyup
to reset search on the select change :
see below snippet :
$(document).ready(function() {
$("select#select").on("change", function() {
// dont know why using below line ?!
location = this.options[this.selectedIndex].value;
$("#idfilteronly").val("");
$("#idfilteronly").trigger("keyup")
});
$("#idfilteronly").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#filteronly> *").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<p>Choose a topic to read</p>
<select id="select" onchange="location = this.options[this.selectedIndex].value;">
<option value=#topic1>Topic 1</option>
<option value=#topic1>Topic 2</option>
<option value=#topic1>Topic 3</option>
</select>
<input id="idfilteronly" maxlength="25" type="text" placeholder="Filter Only..">
<div id="filteronly">
<p id="topic1">This is This is This is This is This is This is This is This is This is This is This is </p>
<p id="topic2">just some just some just some just some just some just some just some just some just some </p>
<p id="topic3">dummy text dummy text dummy text dummy text dummy text dummy text dummy text dummy text </p>
</div>
</body>