Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  36] [ 2]  / answers: 1 / hits: 38974  / 13 Years ago, sun, march 20, 2011, 12:00:00

I've been trying to figure out how to submit the form when the person selects the result from choices of the autocomplete. It needs to work with a mouse click or enter button. I see examples out there but always in pieces. No one shows the entire function.



I have this code below but I get errors saying result is not a function. I don't know how to combine this to do what I would like. Any help is appreciated.



jQuery(document).ready(function(){  

jQuery(#vsearch).autocomplete(ajax/search.php,
{
minLength: 2
}
);
jQuery(#vsearch).result(function(event, data, formatted) {
jQuery('#vsearch').value( formatted );
jQuery('#search').submit();
});
});

More From » jquery

 Answers
5

From: http://api.jqueryui.com/autocomplete/#event-select




select - Type:autocompleteselect



Triggered when an item is selected
from the menu; ui.item refers to the
selected item. The default action of
select is to replace the text field's
value with the value of the selected
item. Canceling this event prevents
the value from being updated, but does
not prevent the menu from closing.



Code examples



Supply a callback function to handle
the select event as an init option.



$( .selector ).autocomplete({
select: function(event, ui) { ... }
});


Bind to the select event by type:
autocompleteselect.



$( .selector ).bind( autocompleteselect, function(event, ui) {
...
});



So you would use:



EDIT: (modified in case user does not select anything)



$(#vsearch).autocomplete({
source: ajax/search.php,
minLength: 2,
select: function(event, ui) {
if(ui.item){
$('#vsearch').val(ui.item.value);
}
$('#search').submit();
}
});


If I am sure of what you are wanting to do.


[#93180] Friday, March 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
;