I'm trying to normalize some user input on a form, and I thought Jörn's autocomplete would fit the bill, except I'm having trouble getting the result I need.
Desired behavior - user can type either the abbreviation for their state or begin typing the state name, and autocomplete will return the most likely result. e.g. Entering a non-case-sensitive "va" would ideally return "Virginia", as would "vi" Actual behavior - entering "va" returns Ne*va*da, Pennsyl*va*nia, Virginia in that order. Entering "vi" returns Virginia, as expected. Of course, setting matchContains to false, only lets it match the abbreviation: "va" returns Virginia, but "vi" doesn't return anything. I'm not sure how to go about getting the results I'm looking for. Any help would be appreciated. Code follows: var statesabbv = [ {abbv: "AL", name: "Alabama"}, {abbv: "AK", name: "Alaska"}, {abbv: "AR", name: "Arkansas"}, {abbv: "AZ", name: "Arizona"}, {abbv: "CA", name: "California"}, {abbv: "CO", name: "Colorado"}, {abbv: "CT", name: "Connecticut"}, {abbv: "DE", name: "Delaware"}, {abbv: "FL", name: "Florida"}, {abbv: "GA", name: "Georgia"}, {abbv: "HI", name: "Hawaii"}, {abbv: "ID", name: "Idaho"}, {abbv: "IL", name: "Illinois"}, {abbv: "IN", name: "Indiana"}, {abbv: "IA", name: "Iowa"}, {abbv: "KS", name: "Kansas"}, {abbv: "KY", name: "Kentucky"}, {abbv: "LA", name: "Louisiana"}, {abbv: "ME", name: "Maine"}, {abbv: "MD", name: "Maryland"}, {abbv: "MA", name: "Massachusetts"}, {abbv: "MI", name: "Michigan"}, {abbv: "MN", name: "Minnesota"}, {abbv: "MS", name: "Mississippi"}, {abbv: "MO", name: "Missouri"}, {abbv: "MT", name: "Montana"}, {abbv: "NE", name: "Nebraska"}, {abbv: "NV", name: "Nevada"}, {abbv: "NH", name: "New Hampshire"}, {abbv: "NJ", name: "New Jersey"}, {abbv: "NM", name: "New Mexico"}, {abbv: "NY", name: "New York"}, {abbv: "NC", name: "North Carolina"}, {abbv: "ND", name: "North Dakota"}, {abbv: "OH", name: "Ohio"}, {abbv: "OK", name: "Oklahoma"}, {abbv: "OR", name: "Oregon"}, {abbv: "PA", name: "Pennsylvania"}, {abbv: "RI", name: "Rhode Island"}, {abbv: "SC", name: "South Carolina"}, {abbv: "SD", name: "South Dakota"}, {abbv: "TN", name: "Tennessee"}, {abbv: "TX", name: "Texas"}, {abbv: "UT", name: "Utah"}, {abbv: "VT", name: "Vermont"}, {abbv: "VA", name: "Virginia"}, {abbv: "WA", name: "Washington"}, {abbv: "WV", name: "West Virginia"}, {abbv: "WI", name: "Wisconsin"}, {abbv: "WY", name: "Wyoming"} ]; jQuery(function($) { $("#state").autocomplete(statesabbv, { minChars: 0, max: 5, delay: 250, matchContains: true, autoFill: false, formatItem: function(row) {return row.name; }, formatMatch: function(row) {return row.abbv + row.name; }, formatResult: function(row) {return row.name; } }); });