$(document).ready(function() {
var count = 5, i, j, el, child;
var container = $('#container');
el = $(document.createElement('select'));
container.append(el);
for (i = 0; i < count; ++i) {
child = $(document.createElement('option'));
child.attr('value', i + 1);
child.text(i + 1);
el.append(child);
}
el.change(function() {
count = parseInt($(this).find(':selected').text());
for (i = 0; i < count; ++i) {
el = $(document.createElement('select'));
container.append(el);
for (j = 0; j < 18; ++j) {
child = $(document.createElement('option')).attr('id', 'child' + i);
child.attr('value', j);
child.text(j);
el.append(child);
}
}
});
});