You can store employee information in a javascript object:
var employees = [
{ id: '1', sex: 'm', city: 'Paris' },
{ id: '2', sex: 'f', city: 'London' },
... etc fill this in a foreach loop
];
Then you are attached to the change event in the selection field:
$(function()
{
$('select#id_of_the_employees_select').change(function(e) {
var selectedEmployeeId = $(this).val();
var emps = $.grep(employees, function(n, i) {
return n.id == selectedEmployeeId;
});
if (emps.length > 0) {
var employee = emps[0];
$('#employee_sex').val(employee.sex);
$('#employee_city').val(employee.city);
}
});
});
source
share