[英]Perl cgi-bin auto complete
I have a very simple website that I built using Perl cgi-bin. 我有一个使用Perl cgi-bin构建的非常简单的网站。 I have one form field that displays all the application codes in my small company.
我有一个表单字段,显示我的小公司中的所有应用程序代码。 Since the application list was small, I used a simple drop down list.
由于应用程序列表很小,因此我使用了一个简单的下拉列表。 However, with growing number of applications, the drop down is turning out to be unmanageable.
但是,随着应用程序数量的增加,下拉列表变得难以管理。 Is it possible to use auto-complete for this field using Perl cgi ?
是否可以使用Perl cgi在此字段中使用自动完成功能?
Edit : The application names are stored in a database table. 编辑:应用程序名称存储在数据库表中。 I pull the application list from the database.
我从数据库中提取应用程序列表。
HTML5 has a nifty tag for Autocomplete Dropdown, <datalist>
. HTML5具有一个用于自动完成下拉菜单的漂亮标签
<datalist>
。 Below is the usage definition for this tag as found on w3schools.com: 以下是在w3schools.com上找到的该标签的用法定义:
Definition and Usage The
<datalist>
tag specifies a list of pre-defined options for an<input>
element.定义和用法
<datalist>
标记为<input>
元素指定预定义选项的列表。The
<datalist>
tag is used to provide an "autocomplete" feature on elements.<datalist>
标记用于在元素上提供“自动完成”功能。 Users will see a drop-down list of pre-defined options as they input data.用户在输入数据时将看到一个预定义选项的下拉列表。
Use the
<input>
element's list attribute to bind it together with a<datalist>
element.使用
<input>
元素的list属性将其与<datalist>
元素绑定在一起。
Code Example: 代码示例:
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
For more details, refer to this link: http://www.w3schools.com/tags/tag_datalist.asp 有关更多详细信息,请参见以下链接: http : //www.w3schools.com/tags/tag_datalist.asp
Alone Perl-CGI it can't do. 单独的Perl-CGI无法做到。
Try to use javascript inside your CGI script. 尝试在CGI脚本中使用javascript。 I added the sample html and javascript below
我在下面添加了示例html和javascript
HTML code HTML代码
<form>
<input type="text" id="someid" onkeyup="myfunc()" style="width:150px"/>
<div id='auto_div' style="position:absolute; width:150px; height:100px;">
</div>
</form>
Javascript with AJAX call 带有AJAX调用的Javascript
function myfunc()
{
var val = document.getElementById("someid").value;
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var res = xmlhttp.responseText;
document.getElementById("auto_div").innerHTML= res;
}
}
xmlhttp.open("GET","database.pl?input_value="+val,true);
xmlhttp.send();
}
Trigger the myfunc
function on every keyup ( onkeyup()
) then get the value of input tag. 在每个keyup(
onkeyup()
)上触发myfunc
函数,然后获取输入标签的值。 Then pass the value from the DB connecting perl file using ajax the result of the output will store into the res
variable then write the conent into the auto_div
然后使用ajax从数据库连接的perl文件中传递值,输出结果将存储到
res
变量中,然后将内容写入auto_div
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.