简体   繁体   English

下拉输入字段

[英]Drop down input field

I have aa drop down field in my search form, but the problem is that I am getting a message: (17 results are available, use up and down arrow keys to navigate.) under the input field instead of results. 我的搜索表单中有一个下拉字段,但问题是我收到一条消息:(17个结果可用,使用向上和向下箭头键导航。)在输入字段下而不是结果。

My code is: 我的代码是:

 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script> 
        <script type="text/javascript">
$(document).ready(function() {
    $(function(){
        $( "#destination" ).autocomplete({
            source: function(request, response) {
                $.ajax({
                url: "http://localhost/fantastic/Travels/search_fields",
                data: { term: $("#destination").val()},
                dataType: "json",
                type: "POST",
               success: function(data){
   var resp = $.map(data,function(obj){
        return obj.destination;
   }); 
   response(resp);
}
            });
        },
        minLength: 1
        });
    });
});
</script>

my controller code is: 我的控制器代码是:

    function search_fields(){
    $term = $this->input->post('term', TRUE);   

     $search_data = $this->Travel->search_field($term); 
     echo json_encode($search_data);

}

My Model code is: 我的模型代码是:

 function search_field($term){

    $query = $this->db->query("SELECT distinct(destination) FROM travels_detail WHERE destination LIKE '".$term."%' group by destination");
    return $query->result_array();
}

I applied the same code to another site and it is working. 我将相同的代码应用到另一个站点,它正在运行。 but on another site its giving me message "17 results are available, use up and down arrow keys to navigate." 但在另一个网站上,它给我的消息“17个结果可用,使用向上和向下箭头键进行导航。” and these 17 results show on keyup and keydown button. 这17个结果显示在keyup和keydown按钮上。

Anyone have some idea?? 任何人都有一些想法? Please tell me 请告诉我

SELECT distinct(destination) FROM travels_detail WHERE destination LIKE '".$term."%' group by destination

You need to drop the group by destination, it's redundant. 您需要按目的地删除组,这是多余的。

Can you try that and let me know how it looks? 你可以尝试一下,让我知道它的样子吗?

It was a matter of css library. 这是一个css库的问题。

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

After placing that library issue is resolved. 放置该库后问题得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM