2

I have state and city dropdown list in an ASP.NET 3.5 application. However, I want city as a textbox, and upon me typing in it, autocomplete mode should occur.

I want to implement it through jQuery, so can anyone please send me the code for this?

Matt
  • 74,352
  • 26
  • 153
  • 180
Manoj Wadhwani
  • 1,487
  • 4
  • 20
  • 23

3 Answers3

4

http://docs.jquery.com/UI/Autocomplete

Menno
  • 536
  • 1
  • 4
  • 10
0

$("#yourtextboxID").autocomplete({source: ["Los Angeles","Las Vegas","Madrid"]});

Alex
  • 14,338
  • 5
  • 41
  • 59
  • Thanks Alexander But tell me one thing how to bind source . This source in C# file which contain id and values of cities . – Manoj Wadhwani Apr 29 '10 at 12:02
  • $("#yourtextboxID").autocomplete( { source: [{value:1, label: "Los Angeles"},{value:2, label: "Las Vegas"},{value:3, label: "Madrid"}], select: function(event, ui) { $('#yourtextboxID').val(ui.item.label); $('#yourhiddenfieldID').val(ui.item.value); return false; } }); – Alex Apr 29 '10 at 12:25
  • Thanks for you help. But i want to give source from c# function to in source there sould be function how can i call function in source : – Manoj Wadhwani Apr 29 '10 at 14:28
0

The most straightforward way is to use the jQuery Autocompleye plugin.

If that doesn't tickle your fancy, try checking out this question. If you're having problems specifically with Asp.NET in conjunction with jQuery and AJAX, it looks like this question may be of use as well.

Community
  • 1
  • 1
Richard JP Le Guen
  • 28,364
  • 7
  • 89
  • 119