1

Possible Duplicate:
need gmail like functionailty - jquery autocomplete to include names and email addresses - in string searching

When user types in xxx,autocomplete with a list of xxx@gmail.com,xxx@msn.com and so on?

Community
  • 1
  • 1
mysql_go
  • 2,269
  • 4
  • 20
  • 20
  • You mean something like this? http://stackoverflow.com/questions/1300091/need-gmail-like-functionailty-jquery-autocomplete-to-include-names-and-email-ad – canadiancreed Mar 19 '11 at 04:27
  • How is it supposed to guess which domain to auto-complete? Literally any domain is capable of receiving email. – user229044 Mar 19 '11 at 04:27
  • Use an autocomplete which can use an array and build the array (or json I guess) and build it on the fly based on user input and your static list of domains. Pretty straight forward. – Brettski Mar 19 '11 at 04:31

1 Answers1

4

Try something like this:

var options = ['@gmail.com', '@msn.com', '@yahoo.com'];
$("input#autocomplete").autocomplete({
    source: options
});
$("input#autocomplete").keyup(function() {
    var new_options = [];
    for (var i = 0; i < options.length; i++)
        new_options[i] = $(this).val() + options[i];
    $(this).autocomplete( "option", "source", new_options);
});

Look at it working here.

cambraca
  • 27,014
  • 16
  • 68
  • 99
  • I know there are some inefficiencies here, like calling a global variable from inside a function a lot of times and so on, but this is only illustrative :) – cambraca Mar 19 '11 at 04:32