Import your jQuery javascript file. Then in your html or external script:
$(document).ready(function() {
$(function() {
$("select#companies").change(function() {
$.getJSON("Companies.action?emmployees=",{companyID: $(this).val(), ajax: 'true'}, function(j){
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].value + '">' + j[i].label + '</option>';
}
$("select#employees").html(options);
})
})
})
});
My initial select has an id "companies" (ie <select id="companies"). The select to populate is simply defined as:
<select name="employeeID" id="employees"></select>
The server side component just needs to return json with your employees objects with fields "label" and "value"
No comments :
Post a Comment