dongqian3198 2017-02-01 06:07
浏览 58

使用php [copy]在文本框中自动提示

This question already has an answer here:

Whenever I input letter 'a' it suggesting all the name with letter 'a' in the name_table. I want to to make it suggest only the name that start with letter 'a'. How to fix this?.

index.php

<html><script type="text/javascript">
$(function() {
    var availableTags = <?php include('autocomplete.php'); ?>;
    $("#first_name").autocomplete({
        source: availableTags,
        autoFocus:true
    });
});
</script>
<form>
<label class="w3-label w3-text-green">Name</label>
<input class="w3-input w3-border" style="height: 30px" type="text" id="first_name" name = "name" required>
</form>
</html>

autocomplete.php

<?php
require('connection.php');
$sql = "select name from employee";
$result = mysqli_query($conn, $sql) or die("Error " .
mysqli_error($connection));

$dname_list = array();
while($row = mysqli_fetch_array($result))
{
$fullname = $row['name'];

$dname_list[] = $fullname;
}
echo json_encode($dname_list);
?>
</div>
  • 写回答

2条回答 默认 最新

  • doubi12138 2017-02-01 06:20
    关注

    I suggest you to use ajax with PHP for getting the autocomplete results on keyup(when some key is pressed and released, JS provides this function).

    This is pretty simple and straighforward tutorial on PHP-AJAX-Autocomplete http://papermashup.com/jquery-php-ajax-autosuggest/

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器