Currently the autoplete action when pressing the Enter key on a selected element is to put that elements value into the input box.
How can I modify the behavior so that pressing the Enter key on an element triggers that elements embedded url. To simplify I'd like to make the Enter key have the same behavior as a mouse click on a returned element.
Thanks
Currently the autoplete action when pressing the Enter key on a selected element is to put that elements value into the input box.
How can I modify the behavior so that pressing the Enter key on an element triggers that elements embedded url. To simplify I'd like to make the Enter key have the same behavior as a mouse click on a returned element.
Thanks
Share Improve this question edited Jun 16, 2016 at 0:17 user6214440 asked Oct 21, 2010 at 13:09 speckedspecked 1454 silver badges11 bronze badges3 Answers
Reset to default 3Easy !
$(".quicksearch-input").autoplete({
minLength: 4, // minimum length to trigger suggestions
// ... + other configuration options
select: function(e, ui) { // define select handler
var uri = ui.item.link; // where ui.item.link itself is defined in your object which you posing when retrieving JSON from endpoint
window.location = uri; // forwarding to the URL obtained
}, // select //
});
But everything depends on your way of implementation.
This is the function that is called when you select an item and hit enter. The hacky code you see in this function extracts the href from the link and redirects to that url.
$("#searchBox").result(function(event, data, formatted) {
var p = data.toString();
p = p.replace('<a href="', '');
var url = p.substr(0, p.indexOf('"'));
p = p.replace('</a>', '');
p = p.substr(p.indexOf('>') + 1, p.length - p.indexOf('>') - 1);
window.location = "" + url;
return false;
});
Did you try keypress event
have a look on the events
http://api.jquery./keypress/
http://api.jquery./category/events/keyboard-events/
http://api.jquery./category/events/mouse-events/