I wanted to use the auto complete widget to allow someone to select an employee by typing in an employee name into the text box, but I want the form to post the ID of the employee, not the employee name.I provided the data ie the employee names as source. the label and value in the .js is same as the source i provided how can i possible to get employee name and id separate.
$("#txtEmployeeName").autocomplete({
var suggestions = [] ;
//define callback to format results
source: function(req, add){
ajax call...
on success: function( data )
{
suggestions = data.split('|');
add(suggestions);
}
select: function(e, ui) {
//create formatted friend
var friend = ui.item.value,
span = $("<span>").text(friend)
$("#"+ $(this).attr("id")).val(span);
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…