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
- $('#select_client').changeSelect(url, route);
But I am only able to call the function like
- $().changeSelect(url, 'client', '#select_client');
Where is my mistake in the handling of the variables in the function?
Here is my function:
- $.fn.changeSelect = function(url, route, field){
- $.getJSON(url+route, function(result){
- var items="";
- $.each(result, function(i, data){
- items+="<option value='"+data.id+"'>"+data.name+"</option>";
- });
- $(field).append(items);
- });
- }
Thanks for any help!
Andy