function not modifying elemt properly

function not modifying elemt properly

Hi,

I have defined a function which gets JSON arrays and converts them into options for selects. Actually it does what it should do but only with a kind of workaround.

I want to call the function like
  1. $('#select_client').changeSelect(url, route);
But I am only able to call the function like
  1. $().changeSelect(url, 'client', '#select_client');
Where is my mistake in the handling of the variables in the function?

Here is my function:
  1. $.fn.changeSelect = function(url, route, field){
  2.         $.getJSON(url+route, function(result){
  3.                 var items="";
  4.                 $.each(result, function(i, data){
  5.                         items+="<option value='"+data.id+"'>"+data.name+"</option>";
  6.                 });
  7.         $(field).append(items);
  8.     });
  9. }
Thanks for any help!

Andy