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++) {
			delimiter: null, // regex or character
			deferRequestBy: 50, //miliseconds
			// callback function:
			onSelect: function(value, data){ 
			    alert('You selected: ' + value + ', ' + data); 
			    alert('val: '+
                             'CompanyId').val() + 'object?: '+
    } else {
	alert('You must first specify how many companies are in the list.');
    return false;