I use easyautocomplete plugin(http://easyautocomplete.com/guide), I use some custom JavaScript to bind keydown event to search input which redirect the page to suggestion page when user press "ENTER" , But it redirects the page even when the user selects an item from suggestion list and press Enter. easyautocomplete provides an "onKeyEnter" event which only triggers when we press "Enter" after selecting an item from suggestions
So this is the custom code I added
jQuery("#input_field").keydown( {
if(e.which == 13) {
document.location = "/search_results.php";
}
});
So I need to stop this redirection when we press Enter after choosing any item from suggestion list by up arrow and down arrow key.
easyautocomplete has already an event handler to capture the "Enter" press on list suggestions only, i.e that event function will not be captured when we simply press Enter on the input field after manually writing something
So what can I do to prevent that redirect in that eventHandler's function
onKeyEnter : function(){
// stop redirect
.........
.......
}
I don't want to permanently remove the "redirect " action from the input, just want to avoid it in particular case that is why I can't use .off()
Thanks!
UPDATE
I am not sure if it is the best method but window.stop()
did the job for me
jQuery("#input_field").keydown( {
if(e.which == 13) {
document.location = "/search_results.php";
}
});
onKeyEnter : function(){ // press Enter on the search suggestions
window.stop(); // stop the redirecting
}
Thanks!