Populate A Box With Another
Solution 1:
You could subscribe to the change event of the first select box and then trigger an ajax request to your server by passing the selected value. Then in the success callback of this request you could use the JSON array returned by the server to update the contents of the second select box. Here's an example of how to achieve this using jQuery:
$(function() {
$('.class').change(function() {
// when the value of the first select changes trigger an ajax requestvar value = $(this).val();
$.getJSON('/script.cgi', { selectedValue: value }, function(result) {
// assuming the server returned json update the contents of the // second selectboxvar subject = $('.subject');
subject.empty();
$.each(result, function(index, item) {
result.append(
$('<option/>', {
value: item.valuetext: item.text
})
);
});
});
});
});
and the JSON returned from the server could look like this:
[ { value: '1', text: 'subject 1' }, { value: '2', text: 'subject 2' } ]
Post a Comment for "Populate A Box With Another"