views:

23

answers:

0

Hi,

I use jQuery Autocomplete plugin. http://docs.jquery.com/Plugins/Autocomplete

I use it for an employee list. Once an employee is selected from the list, a hidden field is set with that employee's ID.

But if I copied and pasted an employee or manually type employee name (without selecting from the list), the hidden field is not set.

Following is my code. "txtEmpName" is the text field Autocomplete is set and "hdnEmpId" is the hidden field.

Is there any improvement I can make to make it work in 'on-change' of "txtEmpName".

Thanks.


var empdata =  [{name:'David Palmer',id:'1'},{name:'Jack Bauer',id:'2'}];
$("#txtEmpName").autocomplete(empdata, {
    formatItem: function(item) {
        return item.name;
    }, matchContains:"word"
}).result(function(event, item) {
      $('#hdnEmpId').val(item.id);
});