Reputation: 12575
In Jquery when i select the matched record, i want to allow only numbers in the selected record to be placed in the textbox. i want to know how to do this in autocomplete. for example
when i type 75 in the textbox it gives me the results like below
7510- Synaptic
7512-Allied
7513-King
when i select the particular row , the number in the seleted value should only be placed in the textbox.
-- > 7513-King
7513 should be placed in textbox.
Upvotes: 1
Views: 1859
Reputation: 6013
This can be done with the original standalone jQuery autocompleter plugin that is still around (and actively developed):
http://code.google.com/p/jquery-autocomplete/
You will have to use the option
onItemSelect
There is an example that does just this in the demo (http://code.google.com/p/jquery-autocomplete/source/browse/demo/index.html)
Upvotes: 0
Reputation: 24506
Are you using the jQuery UI autocomplete ? If so, pass in an initial array of Json objects with both label and value properties. The label text will be displayed in the autocomplete dropdown, but the value is available on the select event.
var data = [
{ label: "7510-Synaptic", value: 7510 },
{ label: "7512-Allied", value: 7512 },
{ label: "7513-King", value: 7513 }
];
$( "#theAutocomplete" ).autocomplete({
delay: 0,
source: data,
select: function(event, ui) {
// selected value is at ui.item.value;
// label is at ui.item.label
}
}).
Upvotes: 4
Reputation: 10981
This should do it, although a regex expression would be also usefull and maybe more accurate.
parseInt('7513-King');
Upvotes: 0