2012-04-08 12 views
2

jquerysの有名なオートコンプリートを使ってオートコンプリートフィールドを作成しようとしていて、mysqlデータベースから配列を作成しようとしています。それは完全に動作しますが、選択が行われると、入力フィールドの値は更新されないため、フォームから値を渡すことができません。誰かがここで私を助けることができる?Jqueryのオートコンプリートで選択項目の入力値が更新されない

のjQuery:

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/base/jquery-ui.css " type="text/css" media="all" /> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js " type="text/javascript"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js " type="text/javascript"></script> 
<script> 
$(document).ready(function() { 
    $("#keywords").autocomplete({ 
    source: keywordList 
    }); 
}); 

</script> 
<?php echo keywordArray(); ?> 

PHP:(オートコンプリートのための配列リストを作成する)

<?php 
include 'admin/dbconn-dest.php'; 

function keywordArray() 
{ 
    $rsKeywords = mysql_query("SELECT Destination FROM Destinations WHERE Country = 'Mexico'"); 

    $output = '<script>'."\n"; 
    $output .= 'var keywordList = ['; 

    while($row_rsKeywords = mysql_fetch_assoc($rsKeywords)) 
    { 
    $output .= '"'.$row_rsKeywords['Destination'].'",'; 
    } 

    $output = substr($output,0,-1); //Get rid of the trailing comma 
    $output .= '];'."\n"; 
    $output .= '</script>'; 
    return $output; 
} 
?> 

HTML:

<input id="keywords" name="keywords" type="text" autocomplete="off" size="40" > 

任意の助けいただければ幸いです!

+0

の値を設定するには? –

答えて

4

使用する]を選択eventあなたは[jsfiddle](http://www.jsfiddle.net)を実証する問題を投稿することができ、入力ボックス

$("#keywords").autocomplete({ 
    source: keywordList, 
    select: function (event, ui) { 
         $("#keywords").val(ui.item.value);      
        } 
    }); 
+0

ありがとうございます! – lov2code

1

これは既知の問題です。 Select Firstプラグインを試してみてください。これはあなたのために仕事をする必要があります(少なくともそれは私のケースでは完璧に機能しました)

希望に役立ちます。

関連する問題