jQuery的自动完成不更新与选择的输入值 [英] Jquery autocomplete not updating the input value with selection

查看:111
本文介绍了jQuery的自动完成不更新与选择的输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建jquerys著名自动完成,并通过创建从MySQL数据库阵列自动填充字段。它完美,但当做出选择,不更新输入字段的值,所以我不能够从表单传递值。有人可以帮助我在这里?

I am trying to create an autocomplete field with jquerys famous autocomplete and by creating an array from mysql database. It works perfectly but when a selection is made, the input field value is not updated, therefore I am not able to pass the value from the form. Can someone help me here?

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: (to create array list for autocomplete)

<?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" >

任何帮助将大大AP preciated!

Any help would be greatly appreciated!!!

推荐答案

使用选择事件来设置输入框的值

Use the select event to set the value of the input box

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

这篇关于jQuery的自动完成不更新与选择的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆