Your HTML is malformed (your GetKey
function call is using double quotes inside double quotes). That is causing issues potentially but since you're using Razor I haven't tested it. Your initial function is trying to hook up the event before the element is even defined so that would fail as well. The browser's console window should be showing you errors for these.
Here's the simplest equivalent code to do what you want.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#SearchInput").keyup(function (event) {
var searchText = event.target.value.toLowerCase();
console.log(searchText);
})
})
</script>
</head>
<body>
<ul>
<li class="search">
<a class="fa-search" href="#search">Search</a>
<form id="search" method="get" action="#">
<input id="SearchInput" type="text" name="query" placeholder='@language.Getkey(" search")' />
</form>
</li>
</ul>
</body>
</html>
The HTML you're using isn't the HTML I gave you. Your results won't be like mine. The script blocks, for example, need to be in the
head
of the HTML, not thebody
.The rest of your HTML seems like you are inserting into existing code. The HTML I gave you works without errors and doesn't do what you're seeing. The problem is in your HTML file you dropped it into.
Notice, for example that you're using JQuery inside your event handler to find the search box. But the event already has that. Refer to my code where I use the event to get the target element. Remove your existing keyup script logic and replace it with mine. See if your problems go away.
If they don't then post the entirety of the HTML file you're trying to run but you can leave out things in the body outside the
header
element.