document.getElementById("id_of_textbox")
.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
document.getElementById("id_of_button").click();
}
});
<div class="box">
<div class="container-1">
<form id="something">
<input name="search" placeholder="Search... type ENTER to submit or use the button -->">
<input type="submit">
</form>
<div class="icon" ></div>
</div>
</div>
Run code snippet
// Bind Enter key to search bar
$("#MySearchBar").keypress(function (e) {
if (e.keyCode === 13) {
MyVoidFunction();
}
});
function search(query){
query.preventDefault();
let vquery = query.target.elements["search"].value;
console.log(vquery)
}
something.addEventListener("submit", search, false)
function search(query){
query.preventDefault();
let vquery = query.target.elements["search"].value;
console.log(vquery)
}
something.addEventListener("submit", search, false)
<div class="box">
<div class="container-1">
<form id="something">
<input name="search" placeholder="Search... type ENTER to submit or use the button -->">
<input type="submit">
</form>
<div class="icon" ></div>
</div>
</div>
Run code snippet
<div class="box">
<div class="container-1">
<form id="something">
<input name="search" placeholder="Search... type ENTER to submit or use the button -->">
<input type="submit">
</form>
<div class="icon" ></div>
</div>
</div>
Run code snippet