Home > Programming, jQuery > Using ui autocomplete as a dropdown, with type in

Using ui autocomplete as a dropdown, with type in

I had been using an autocomplete plugin by bassistance. 2 months later jQuery UI added autocomplete to their list of widgets. Like many plugins out there I was unable to find an autocomplete that was easy to use for my purposes. The closest I recently came to was the sexy combo plugin. I cant remember why but it was just a tad short of what I wanted to do, and I’m still quite a javascript novice.

I came up with a way to use the jQuery UI autocomplete widget as a <select> that you could also type in something if the choices in the dropdown didn’t fit your needs.

ui-autocomplete-dropdown

This example uses a local data source, but you can come up with creative ways to use remote JSON sources if you like.

<script type="text/javascript">
	$(document).ready(function() {

		// dropdown/ auto suggest
		$(".ui_dropdown").autocomplete({
			minLength: 0,
			delay: 0
		});

		$(".ui_dropdown").click(function(){

			var input = $(this);
			var inputID = input.attr('id');

			// close if already visible
			if (input.autocomplete("widget").is(":visible")) {
				input.autocomplete("close");
				return false;
			}

			// set source(s)
			var myData = '';
			if(inputID == 'input1'){
				myData = ["foo","bar","hello","world"];
			} else {
				myData = ["1","2","3","4"];
			}

			// load source
			input.autocomplete({
				source: myData
			});

			// fire search event
			input.autocomplete("search", "");
			input.focus();
			return false;
		});		

	});
</script>

In this script I am using the input id’s to define the data source.

Categories: Programming, jQuery Tags:
  1. May 7th, 2010 at 19:50 | #1

    Great information was shared in this post…
    Thank you for the post..

  2. March 16th, 2011 at 20:44 | #2

    So glad they finally rolled this into the core jquery UI. Nice tutorial – just what i was looking for.

  3. April 7th, 2011 at 00:51 | #3

    Thumbs up! You did have a nice tutorial there and I find it informative and so easy to follow. I am going to try it. Thanks!

  4. June 15th, 2011 at 22:55 | #4

    Great information this is excatly what I have been looking for. Thanks heaps

  5. sad123
    October 19th, 2011 at 22:18 | #5

    Mono Bluetooth Wireless Handfree Headset Headphone N909.N909 Mono Bluetooth Wireless Handfree Headset

  6. fdgfds
  7. sdfasdg
  8. fdhgsfh
    October 27th, 2011 at 00:46 | #8

    Up to 6 hours talk time and 8 days standby time
    Status Display makes it easy to check battery level and Bluetooth connectivity at a glance
    Touch volume control, answer/end button, voice dialing (depending on the phone used)
    Streams music from A2DP-enabled mobile phones
    Connect two Bluetooth enabled devices at the same time with Multiuse capabilities Stainless Survival Tool

  9. October 27th, 2011 at 07:43 | #9

    i am facing the problem in this step… but after reading this article i solved my problem… thnaks for sharing thios information..

  10. November 11th, 2011 at 05:33 | #10

    I learn a lot from this post,thank you!

  11. December 6th, 2011 at 01:29 | #11

    Nice, just to let you know the post isnt showing up properly on my iphone – I think there is a plugin you can grab that takes care of that now.

  12. December 9th, 2011 at 04:13 | #12

    Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

  13. December 15th, 2011 at 02:35 | #13

    This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource

  14. December 16th, 2011 at 22:56 | #14

    THANKYO

  15. January 9th, 2012 at 04:26 | #15
  16. January 11th, 2012 at 04:46 | #16

    Aw, this was a really quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done.

  17. February 3rd, 2012 at 08:45 | #17

    I found very useful and interesting posts in this blog which is the great signs for a good blogger.

  18. February 3rd, 2012 at 08:46 | #18

    Congratulation for the great post. Those who come to read your article will find lots of helpful and informative tips.

  19. February 3rd, 2012 at 08:48 | #19

    Nice post with awesome points! Can’t wait for the next one.

  20. February 3rd, 2012 at 08:49 | #20

    Nice post with loving snapshot. I am completely impressed! Keep stuff like this coming

  21. February 3rd, 2012 at 08:51 | #21

    Very nice post even i would say that whole blog is awesome. I keep learning new things every day from post like these. Good stuff!

  22. February 9th, 2012 at 02:40 | #22

    Due to such type of scripts the pc lags to open this. but i use a system utility tool to fix pc. Thanks for sharing this information.

  23. March 4th, 2012 at 22:01 | #23

    WJZLXZYSWMLGRL
    Voici le prochain ajout certainement superbe pour votre garde-robe. Un sac Adjani Lancel .

  24. March 15th, 2012 at 03:08 | #24

    Great article! I am agree with the writer’s way of thinking.
    The failure of info usually leads a person to some a sense of discouragement.
    So that you can solve this challenge, the specialists have launched a lot of info restoration solutions.
    Just in case of data deletion condition, a user needs to have a knowledge of appropriate important information recovery tool.

  25. March 18th, 2012 at 19:26 | #25

    Valuable information ..I am delighted to read this article..thank you for giving us this useful information. Great walk-through. I value this post.

  26. March 19th, 2012 at 04:04 | #26

    This Coach Factory O so cool. I am such a huge fan of their work. I really am impressed with how much you have worked to make this website so enjoyable.

  27. March 26th, 2012 at 02:30 | #27

    Deceptive only temporary, and integrity is a long-term strategy. When credit disappeared when the body, there is no life. If you want others to integrity, to our own integrity

  28. March 30th, 2012 at 03:01 | #28

    Tout n’est que la lèvre, Nike Air Max Shoes la sagesse qui veut l’expérience. Expericence est un professeur dur parce qu’elle donne le premier test,Nike Air Max Shoes la le?on afterwards.Law Vernon, writer.Experience britannique n’est pas intéressante jusqu’à ce qu’il commence à se répéter, en fait, jusqu’à il le fait , il n’est guère d’expérience louis vuitton Site Officiel.

  29. April 5th, 2012 at 22:30 | #29

    because the ultraviolet is so strong ,we need oakley sunglasses to protect our eyes.

  30. April 8th, 2012 at 23:05 | #30

    A good article, worth sharing for you, see you your article to your future success believe a great help, hope to see more of you share good article, thank you for sharing

  31. April 9th, 2012 at 02:38 | #31

    No honest what dignity, when l was gone, the body does not have the life, faith is the supreme virtue, half the truth is often a palpable lies, sincere person, way of heaven; person of sincerity, the way of the.

  32. April 19th, 2012 at 00:20 | #32

    OPEL car is usually highly popular and recommended for their good performance 100Z

  33. April 24th, 2012 at 10:20 | #33

    Center Joel-Anthony and dexter-pittman called the Miami heat star won the upper during the opportunity Stitched Jerseys, pittman for three consecutive games start, Anthony have more chance to attack, Houston yesterday just 5 of 5 to 11 points and a season-high. “This help us, as he played very well Cheap Ravens Jerseys, I think this is great, especially for a young player character, rotation player has more opportunities, this is good for us in the playoffs,” Anthony said. “personally cheap jerseys, I get more, you know your position on the pitch, it is the most important, his teammates can find me.”

  34. April 26th, 2012 at 11:14 | #34

    Yes old school push ups are very effective for burning up fat. At first they can seem daunting but you’ll progress fast as you master your personal pounds before moving on to more advanced chest presses like the bench press.

  35. April 28th, 2012 at 10:09 | #35

    Keep in mind you’re attempting to construct some muscle mass around your stomach while burning weight. Avoid starving your self and make sure you remain complete all day time without overdoing it. It is all about balance when trying to obtain washboard abs.

  36. April 28th, 2012 at 11:26 | #36

    Sticking with the best workouts, you have to do is weight training. The best ab training workouts are not the boring crunches and situps that you are used to doing. Remember, an ab physical exercise has to do two things. Move your torso toward your hip or hip toward your torso AND supply resistance in this motion. Perform your ab muscles like you perform every other muscle and you will see fantastic outcomes.

  37. April 28th, 2012 at 13:26 | #37

    Obtaining washboard abdominals isn’t about performing a ton of basic crunches every day time. It’s not about purchasing the most costly equipment you see on TV or some type of magic pill that will do it for you personally.

  38. April 28th, 2012 at 16:10 | #38

    Begin doing effective ab exercises like reverse ab crunches. These are done by laying about the floor together with your legs up in the air. Bend your knees at about 90 degrees then bring your keens back to touch your chest. Go back towards the starting position and you may have completed the rep.

  39. April 28th, 2012 at 17:44 | #39

    You also need to do full entire body pounds training to melt away calories from fat all over because in the big scheme of the body, your abdominals are little muscle tissues and do not do a great deal for the metabolism when you stimulate them.

  40. April 28th, 2012 at 23:28 | #40

    A great deal of individuals who have tried this kind of diet plan plan has claimed that they indeed lose weight without having the have to physical exercise, but most specialists nevertheless insists of going through an exercise routine since it can be a lot healthier and can assist you shed pounds and burn fats rapidly.

  41. April 29th, 2012 at 07:32 | #41

    These ideas can be really useful in obtaining washboard abs quick, but should you really want to construct stunning six pack abs, you will find a few insider secrets used by all of the top body builders, in buy to get ripped truly fast. By following their techniques you can get the same outcomes.

  1. April 1st, 2010 at 10:31 | #1
  2. April 1st, 2010 at 11:10 | #2
  3. April 1st, 2010 at 11:28 | #3
  4. April 1st, 2010 at 11:36 | #4
  5. April 1st, 2010 at 11:50 | #5
  6. April 1st, 2010 at 11:54 | #6
  7. April 1st, 2010 at 12:03 | #7
  8. April 1st, 2010 at 12:09 | #8
  9. April 1st, 2010 at 12:11 | #9
  10. April 1st, 2010 at 12:16 | #10
  11. April 1st, 2010 at 12:27 | #11
  12. April 1st, 2010 at 12:28 | #12
  13. April 1st, 2010 at 12:28 | #13
  14. April 1st, 2010 at 14:09 | #14
  15. April 1st, 2010 at 14:46 | #15
  16. April 1st, 2010 at 14:54 | #16
  17. April 1st, 2010 at 15:24 | #17
  18. April 1st, 2010 at 15:33 | #18
  19. April 8th, 2010 at 15:09 | #19