I need to implement a drop-down menu in my HTML page which has over 2000 firm names.Embedding such a huge list in the html page will make it huge and slow to load.So wanted to know if there is an interactive mechanism in OpenCPU/RApache to fetch the same interactively.Like if user types A, it should show all the company names starting with letter "A"...
3 Answers
From within an HTML page, the only way to interactively fetch data from the server without reloading the page is to use AJAX. And you could possibly create an array that holds all of the values that were fetched, so that you don't have to refetch names that have already been retrieved.
On the server, you would need to create a page that returns a list of business names depending on some criteria, such as a letter typed by the user.
UPDATE
Also, have you actually tested a page with 2000 items in the dropdown? Do you know that it will be slow? If each item was 40 characters long, that would be 80K of text. A browser can process 80K in mere milliseconds. The issue, I think, is not a problem with the load time, but rather forcing your users to scroll through a list with 2000 entries.
UPDATE 2
I just did an open Google search for "how to create ajax dropdown with php". Here's an example that is similar to yours.. the major concepts are covered. Though you would trigger your AJAX call based on the onkeyup
event on a textbox.

- 7,254
- 2
- 28
- 44
-
ajax is not the only way, but it's if you want complete compatibility – ncubica Nov 28 '12 at 19:55
Man what you need is an autocomplet widget using jquery:
http://jqueryui.com/autocomplete/
And if you want to do it without any javascript you can do it whit html5 of course with the limitation of compatibility.
http://css-tricks.com/relevant-dropdowns-polyfill-for-datalist/

- 8,169
- 9
- 54
- 72
-
thanks guys, I have't tried 2000 company names but presumed it will be slow to load, will try the autocomplete feature. does it work only for list of one word tags or also multi-word phrases. My firmnames will be multi-word like "Berkshire Hathaway", "Tata Iron and Steel Co" etc. – user1783870 Nov 28 '12 at 20:16
-
The autocomplete depends of the query in you sql here is an example how to implemented in php myslq, I think you are using another kind of tech but could work for you http://af-design.com/blog/2010/05/12/using-jquery-uis-autocomplete-to-populate-a-form/ mark the answer as correct if this work or help you :) – ncubica Nov 28 '12 at 20:35
I faced a similar problem in an R-backed web application that I developed. I needed to offer the user a selection list based on 12,000 gene symbols and I wanted to let them type in partial symbols. I ended up using Select2 which is based on JQuery. You do end up using an ajax call from the web page back to an R function. In my case, I had, on the server side, a function that received the characters as the user typed and produced a partial list (in JSON) to return. I required the user to type in at least two characters in order to make the list smaller. It worked well for my application.

- 31
- 2