I am trying to implement a jquery autocomplete plugin. Everything works for me, but something does not work properly.
Basically, I have an autocomplete list of employees. The list is created from the table in the sql database (employee_names and employee_ID) using the VB.NET handler (.ashx file). Data is formatted as: employee_name-employee_ID. So far, so good, and all employees are listed in auto-complete.
The problem is that I donβt know how to redirect the user to a specific page (e.g. employee_profile.aspx) when they selected the employee from autocomplete.
This is my redirect code, but it does not work as it should:
$('#fname2').result(function(event, data, formatted) { location.href = "employee_profile.aspx?id=" + data });
For instance; user selects. Will he redirect the user to employee_profile.aspx? Id = name of employee-employee identifier (for example: employee_profile.aspx? Id = John Doe-91210) instead of employee_profile.aspx? Id = 91210.
I know I can remove employee_ID with:
formatResult: function(data, value) { return value.split("-")[1]; } });
But I donβt know how to pass this employee_ID to the redirect page.
Here is all my code:
$().ready(function() { $("#fname2").autocomplete("AutocompleteData.ashx", { minChars: 3, selectFirst: false, formatItem: function(data, i, n, value) { return value.split("-")[0]; },
I know that I am very close, and it should be something really simple, but can someone help me?
EDIT
This solved it for me: formatted.split instead of data.split. The code:
$('#fname3').result(function(event, data, formatted) { var employeeId = formatted.split("-")[1]; location.href = "employee_profile.aspx?id=" + employeeId });