Lets say i have function with id paremeter and two select box
<select id="one" onchange="Fill(2)"></select>
<select id="two" onchange="Fill(3)"></select>
<select id="three"></select>
My function
function Fill(id){
//some manupulation
$('<option/>').val(substr[0]).html(substr[1]).appendTo('#two');
}
But instead of doing many
if(id==2) {$('<option/>').val(substr[0]).html(substr[1]).appendTo('#two');}
if(id==3) {$('<option/>').val(substr[0]).html(substr[1]).appendTo('#three');}
i want something like
$('<option/>').val(substr[0]).html(substr[1]).appendTo(DYNAMIC);
You could make it much easier by using ids such as
select-1,select-2etc. and then use'#select-' + id.Otherwise you need a mapping object which maps from digits to spelled numbers.