オートコンプリートを備えた単純なテキスト入力があります。
<input type="text" class="span4" id="autoc1" name="agent" value="">
次のjqueryコードを使用して、オートコンプリートを実行し、データを戻しています。次に、ワンクリックで、返されたデータで2つの入力を埋めたいと思います。オートコンプリートが設定された実際のフィールドを除いて、すべてが正常に機能します。
Jクエリ:
$(function() {
    // input id of field with autoc on        
    $( "#autoc1" ).autocomplete({
        // php mysql data get
        source: "/pages/includes/getAgent.php",            
        minLength: 2,
        select: function( event, ui ) {
            //alert(ui.item.agent_name); //  shows correct info, here only to test
            //tried $(this) as below - didn't work
            //$(this).val(ui.item.agent_name);
              $('#autoc1').val(ui.item.agent_name); //  tried with and without this, didn't work
              $('#comm').val(ui.item.commission_percent); // this works perfectly!!
        }
    }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li>" )
        .append( "<a>" + item.agent_name + "</a>" )
        .click(function(){$('#autoc1').val(item.agent_name)}) // added this. didn't work
        .appendTo( ul );
    };
});
これは、役立つ場合に返される JSON です。
[{"0":"agent a","agent_name":"agent a","1":"15","commission_percent":"15"},
{"0":"agent b","agent_name":"agent b","1":"10","commission_percent":"10"}]
完全にアイデアが不足しています!
編集
より多くの html、その基本的なフォーム、シンプル
<form class="add_booking" method="post">
    <input type="text" placeholder="Date" class="span2" id="datepicker" name="date" value="<?=$showDate?>">
    <input type="text" placeholder="Booking Agent" class="span4 here" id="autoc1" name="agent" value="<?=$ds['agent']?>">
    <input type="text" placeholder="15" class="span1" name="commission" id="comm" value="<?=$ds['show_comm_percent']?>">%
etc etc </form>