2017-10-03 5 views
1

私はオートコンプリートのテキストボックスを持っています。 テキストボックスで値を選択すると、1つのdivを表示したいとします。 jquery UIの変更機能を試しましたが、正しく機能していません。テキストボックスをクリックするだけで動作します。私は、テキストボックスが最大の価値を得たときに行動を引き起こしたい。私のonselectが機能していません

私は以下の私のコードが含まれていました。

のindex.php

<html> 
    <head> 
     <script type="text/javascript" 
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
     <script type="text/javascript" 
     src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> 
     <link rel="stylesheet" type="text/css" 
     href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" /> 

     <script type="text/javascript"> 
       $(document).ready(function(){ 
        $("#name").autocomplete({ 

         source:'search.php', 
         minLength:1, 

         change: function (event, ui) { alert("hi"); } 

        }); 


       }); 



     </script> 
    </head> 

    <body> 

     <form method="post" action=""> 
      Name : <input type="text" id="name" name="name" /> 
     </form> 

    </body> 
</html> 

あなたが使用することができますオートコンプリートであなたのいずれかのオプションを選択したときに検出するためsearch.php

<?php 
$con=mysqli_connect("localhost","root","","datadb"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

// ...some PHP code for database "my_db"... 

// Change database to "test" 
mysqli_select_db($con,"datadb"); 

// ...some PHP code for database "test"... 


$term=$_GET["term"]; 

$query=mysqli_query($con,"SELECT * FROM user where FirstName like '%".$term."%' GROUP by FirstName "); 
$json=array(); 
if (!$query) { // add this check. 
    die('Invalid query: ' . mysql_error()); 
} 
    while($student=mysqli_fetch_array($query)){ 
     $json[]=array(
        'value'=> $student["FirstName"], 
        'label'=>$student["FirstName"] 
         ); 
    } 

echo json_encode($json); 

?> 
+0

'select'コールバックを見直しましたか? http://api.jqueryui.com/autocomplete/#event-select – Twisty

+0

正確な値がテキストボックスで選択された場合、そのイベントは適用できますか? – user7441072

+0

'select'コールバックは、ユーザがオートコンプリートから選択するとトリガされます。 – Twisty

答えて

0

autocompleteselectイベント...

$("#name").autocomplete({ 
    source: 'search.php', 
    minLength: 1 
}).on('autocompleteselect',function() { 
    // Do your stuff here 
    alert("hi"); 
}); 

私は助けてくれるといいです

関連する問題