Redirecting users on select from autocomplete?
- by juno-2
Hi,
i'm trying to implement the jquery autocomplete plugin.
I've got it up and running, but something is not working properly.
Basically i have a autocomplete-list of employees.
The list is generated from a table in a sql-database (employee_names and employee_ID), using a VB.NET handler (.ashx file). The data is formatted as: employee_name-employee_ID. So far so good and all employees are listed in autocomplete.
The problem is that i don't know how to redirect a user to a certain page (for example employee_profile.aspx) when they've selected an employee from autocomplete.
This is my redirect-code, but it ain't working like it should:
$('#fname2').result(function(event, data, formatted) {
location.href = "employee_profile.aspx?id=" + data
});
For example; a user selects
It will redirect a user to employee_profile.aspx?id=name of employee-id of employee (for example: employee_profile.aspx?id=John Doe-91210) instead of employee_profile.aspx?id=91210.
I know i can strip the employee_ID with:
formatResult: function(data, value) {
return value.split("-")[1];
}
});
But i do not know how to pass that employee_ID to the redirect-page..
Here my whole code:
$().ready(function() {
$("#fname2").autocomplete("AutocompleteData.ashx", {
minChars: 3,
selectFirst: false,
formatItem: function(data, i, n, value) {
return value.split("-")[0];
},
//Not used, just for splitting employee_ID
//formatResult: function(data, value) {
// return value.split("-")[1];
//}
});
$('#fname2').result(function(event, data, formatted) {
location.href = "employee_profile.aspx?id=" + data
});
});
I know i'm very close and it should be something really simple, but can anyone help me out?