2012-05-01 46 views
3

jQuery自動完成選擇事件後,簡單的文本字段更改。我想拆分數據並將其顯示在其他文本字段中。我正在嘗試這個。這根本不會改變任何值。我需要在這裏更改什麼?jQuery - jQuery自動完成選擇事件後的文本字段值更改

$(function() { 
    $("#term").autocomplete({ 
    source: function (request, response) { 
     $.post("https://stackoverflow.com/users/search", request, response); 
    }, 
    minLength: 2, 
    select: function(event, ui){ 
     $('#div2').html(ui.item.value); #doesn't populate with new text. 
     document.getElementById('#found').value="test"; #for test 
     } #doesn't populate with new text. 
      #I want selected data to go here in the 'found' element id 
    }); 
}); 

紅寶石/ HTML -

<%= text_field_tag :found, nil, :maxlength => 11, :size => 20%> 
<input id="found" maxlength="11" name="found" size="20" type="text" /> 
+0

什麼類型的元素是'#found'? –

+0

@AndrewWhitaker - 文本字段。 ''%= text_field_tag:found,nil,:maxlength => 11,:size => 20%>' –

+0

'select'事件是否會觸發?當你在處理程序中放置一個'alert'時會發生什麼? –

回答

4

改變這一行:

document.getElementById('#found').value="test"; #for test 

到:

$('#found').val('test'); 
+0

+1。試過。沒有運氣:/ –

+0

現在怎麼樣?我剛剛更新了它。 –

+0

工作。我想在填充之前分割它。如何分割數據? –