I have a page with 2 listboxes, the main function transfers options from one to the other.
$(function() {
$("#moveright").click(function(){
$("#p_scnt > option:selected").each(function(){
$(this).remove().appendTo("#copy");
});
});
The other part of the page has the option to add an additional set of listboxes
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;
$('#addScnt').on('click', function() {
$('<p><label for="p_scnts"><select size="10" id="p_scnt'+ i +'" name="p_scnt'+ i +'" style="width: 100px;"><option value="volvo">Volvo</option><option value="colvo">Colvo</option><option value="folvo">Folvo</option><option value="bolvo">Bolvo</option></select><input id="moveleft'+ i +'" type="button" value=" < "/><input id="moveright'+ i +'" type="button" value=" > " /> <select size="10" id="copy'+ i +' multiple="multiple" name="copy'+ i +'" style="width: 100px;"></select></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').on('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
The issue I am trying to solve is running the first function for each additional set of listboxes that is created. At the moment it only works on the first one and not the duplicates.