jQuery input value undefined after append

Anyone that can help me out will be very much appreciated. I seem to have got myself into a bit of a kerfuffle.

I'm trying to assign response data - retrieved from an AJAX request using the jquery.autocomplete plugin - to an input element. I can get the response data back fine, but when I try and insert it into the 'value' attribute, nothing happens!

$('#btnPopulate').click(function() {
if ($('#list_length').val() != '') {
	var length = $('#list_length').val();
	var row='';
	for (var i=0; i <= length; i++) {
		row=""+i+"";
		$('#ranking_table').append(row);
		$("CompanyRanking"+i+"CompanyId").autocomplete({ 
			serviceUrl:'/backend/companies/search',
			minChars:2, 
			delimiter: null, // regex or character
			maxHeight:400,
			width:300,
			deferRequestBy: 50, //miliseconds
			// callback function:
			onSelect: function(value, data){ 
			    alert('You selected: ' + value + ', ' + data); 
                                $('#CompanyRanking'+i+'CompanyId').val(data);
			    alert('val: '+
                             $('#CompanyRanking'+i+
                             'CompanyId').val() + 'object?: '+
                             $('#CompanyRanking'+i+'CompanyId'));
		       }
		});
            };
	//$('#btnPopulate').ac;
    } else {
	alert('You must first specify how many companies are in the list.');
};
    return false;
});