To be straightforward, on a page, there is a search input.
var input = document.getElementById('search-input');
function handle(e) {
if (e.keyCode === 13) {
window.location = '../?s=' + input.value;
}
}
<div class="search-form-mobile">
<input type="text" id="search-input" onkeypress="handle(event)" class="form-control" placeholder="Search">
</div>
I know that this is a correct JavaScript
code, but my question is, why does it sometimes accepts the input value and sometimes it doesn't? I've been scratching my head for a while and can't figure out what's wrong.
Should I wrap it up in a <form>
or can i leave it like that?
The <script>
is at the very bottom in footer.php
.
It's a WordPress site.