Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I have jQuery's autocomplete plugin display its dropdown list upon page load?

http://community.sciencecareers.org/mt-static/plugins/CommunityPlus/js/autocomplete/ http://community.sciencecareers.org/mt-static/plugins/CommunityPlus/js/autocomplete/demo/

Trying to programmatically trigger the display of the autocompletion list results. This, instead of waiting for user input.

Is this doable? (I've tried getting the element's focus, calling a Javascript down-arrow key event. No dice)

like image 689
Aaron Fi Avatar asked Dec 01 '09 02:12

Aaron Fi


People also ask

How to enable autocomplete in jQuery?

To enable an autocomplete in jQuery UI, we will be using the enable() method. jQuery UI enable() method is used to enable the autocomplete. It returns the accordion element completely to its initial state.

How do you find the value of autocomplete?

The AutoComplete control supports strongly-typed HTML helpers represented by lambda expressions that have model or template passed into the View. So, you can get the selected value from view in the Controller part. To achieve this, create an AutocompleteFor control and bound the dataSource from controller part.

Which are jQuery UI widgets?

a jQuery UI widget is a specialized jQuery plug-in. Using plug-in, we can apply behaviours to the elements. However, plug-ins lack some built-in capabilities, such as a way to associate data with its elements, expose methods, merge options with defaults, and control the plug-in's lifetime.


2 Answers

If, and only if, you are using a version of jQuery 1.3 or greater, you can create a jQuery.Event object, then trigger() it. I was only able to get it to work if the element is also focused. So this code works for the "E-Mail (local):" example on the demo page.

var e = jQuery.Event("keydown");
e.which = 40;
$('#suggest13').trigger('focus').attr('value',' ').trigger(e);

I'm not sure exactly what your situation is, I think it's somewhat dependent on the autocomplete actually showing something if only a space is pressed. That's not always the case.

like image 67
artlung Avatar answered Oct 18 '22 04:10

artlung


and what about this? $("#autocompleteid").autocomplete("search")

like image 20
simPod Avatar answered Oct 18 '22 05:10

simPod