I have a problem with .each(), i’m trying to iterate over multiple span#obj and use the information from the selection list name=instance_type as a data variable in name=instance_input.
I have it working for a single iteration but if i remove the ‘return false’ from the .each() the data variable becomes filled with the value of the last name=instance_type.
$( "span#obj" ).each(function(){
self = this;
$("[name='instance_input']",this).autocomplete({
source: function( request, response ) {
$.ajax({
url: "json_lookup_call.php",
dataType: "json",
data: {
dataClass : $("[name='instance_type'] :selected",self).val(),
maxRows: 12,
name_startsWith: request.term
},
success: function( data ) {
response( $.map( data.results, function( item ) {
return {
label: item.reference + (item.name ? " - " + item.name : ""),
value: item.reference
}
}));
}
});
},
minLength: 3
});
return false;
});
Try
otherwise you would create a global variable and only the last one would be used, because every iteration overwrites the previous one.