2012-05-01 44 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

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