Possible Duplicate:
How to add dynamically a combobox using jQuery
Look, I’ve this working code for dynamic comboboxs.
<html>
<div id="combos" class="styled-select">
<select id="combo1" class="combo" data-index="1">
<option></option>
<option>sss</option>
<option>aaa</option>
<option>ddd</option>
</select>
</div>
<script>
$('#combos').on('change', '.combo', function () {
var selectedValue = $(this).val();
if ($(this).find('option').size() > 2) {
var newComboBox = $(this).clone();
var thisComboBoxIndex = parseInt($(this).attr('data-index'), 2);
var newComboBoxIndex = thisComboBoxIndex + 1;
$('.parentCombo' + thisComboBoxIndex).remove();
if (selectedValue !== '')
{
newComboBox.attr('data-index', newComboBoxIndex);
newComboBox.attr('id', 'combo' + newComboBoxIndex);
newComboBox.addClass('parentCombo' + thisComboBoxIndex);
newComboBox.find('option[value="' + selectedValue + '"]').remove();
$('#combos').append(newComboBox);
}
}
});
</script>
</html>
What this does is create a new one combobox everytime I fill the combobox before.
What Im looking for is that code create 2 comboboxs everytime I fill the combobox before, instead just one.
How could I do that?
Cheers
Not sure if this what you want but this adds two combo boxes
(after $(‘#combos’).append(newComboBox);):